Input from the keyboard in command line application

Chalkers picture Chalkers · Jun 3, 2014 · Viewed 110.7k times · Source

I am attempting to get the keyboard input for a command line app for the new Apple programming language Swift.

I've scanned the docs to no avail.

import Foundation

println("What is your name?")
???

Any ideas?

Answer

Ezekiel Elin picture Ezekiel Elin · Dec 7, 2015

The correct way to do this is to use readLine, from the Swift Standard Library.

Example:

let response = readLine()

Will give you an Optional value containing the entered text.