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 trialEgor Bedunkevich
643 PointsIs 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
7,551 PointsNot 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
1,043 PointsDairon Castellanos
1,043 PointsIs there any easy way to do this??? , swift is usually a really easy programing language , thats seems bit complicated .