Xcode: Swift String Input in command line

Swift String Input

When I first started with Swift, I didn’t think that a Swift String Input would be a issue. But it seems like at the moment there is no methods of getting a string input from terminal or console. You will have to use some Objective C statements to achieve this. They are easily accessible so there is no problem in getting them. You can paste this code and create your own Input method. Here is the Swift String input code:

The way you want to use this, is about the same way as with some sort of C language.
print("Enter> ")
var string1 = input()
println("You typed: " + string1)

You can also do it in a “one liner” if you only need to do it once. If you need to do this more than once, I would just go with the first method. Because the printing of the result is also a bit more to it now, as you need to convert it from a NSString to a string.