Swift get user input with prompt
Question: In Swift, I want to have a continous user-input loop, much like how the python
interpreter works, where a prompt is made, you type a line, the result of the
line is displayed, and then the user is prompted again. This is my code so
far:

    
    
    import Foundation
    
    func input() -> String {
        var keyboard = NSFileHandle.fileHandleWithStandardInput()
        var inputData = keyboard.availableData
        return NSString(data: inputData, encoding: NSUTF8StringEncoding) as! String
    }
    while true {
        println("Obl>")
        var theInput = input()
        println("\(theInput)")
    
    }
    

However, this results in a scheme like this:

    
    
    Obl>
    hello world
    hello world
    Obl>
    yo
    yo
    

What I want it to look like is this:

    
    
    Obl> hello world
    hello world
    Obl> hello
    hello
    

How can this be accomplished?


Answer: Are you still using Swift 1? `println` has been deprecated in Swift 2.

Swift 1:

    
    
    print("Obl> ")
    

Swift 2:

    
    
    print("Obl>", terminator: " ")
    

And instead of your `input()` function, you can just use `readLine`, which is
a standard function in Swift:

    
    
    let theInput = readLine()
    

