Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Egor Bedunkevich
Egor Bedunkevich
643 Points

Is there a way to ask for user input in Swift?

When creating a console application, can I somehow ask for user input?

1 Answer

Dustin Morgan
Dustin Morgan
7,551 Points

Not easily but yes you can do it.

Import Foundation

func input() -> String {
    var keyboard = NSFileHandle.fileHandleWithStandardInput()
    var inputData = keyboard.availableData
    return NSString(data: inputData, encoding: NSUTF8StringEncoding) as! String
}
println("Please enter your input..")
var theInput = input()
println("\(theInput)")
Dairon Castellanos
Dairon Castellanos
1,043 Points

Is there any easy way to do this??? , swift is usually a really easy programing language , thats seems bit complicated .