This is actually not easy in Swift at this point. The simplest way is probably the Objective-C way, using an NSFileHandle with standard input:
import Foundation
var fh = NSFileHandle.fileHandleWithStandardInput()
println("What is your name?")
if let data = fh.availableData {
var str = NSString(data: data, encoding: NSUTF8StringEncoding)
println("Your name is \(str)")
}
Or for continuous input:
println("I will repeat strings back at you:")
waitingOnInput: while true {
if let data = fh.availableData {
var str = NSString(data: data, encoding: NSUTF8StringEncoding)
println(str)
}
}
The possible encodings are shown here.