Skip to content

Instantly share code, notes, and snippets.

@Darmaal
Created September 5, 2016 11:02
Show Gist options
  • Save Darmaal/241c87d9efda8df1b708760a04793022 to your computer and use it in GitHub Desktop.
Save Darmaal/241c87d9efda8df1b708760a04793022 to your computer and use it in GitHub Desktop.
import Foundation
//this file is to get the user input --> processor
//return a string --> which is the user input --> we use foundational classes provided by Apple
func getUserInput() -> String {
let standardInput = NSFileHandle.fileHandleWithStandardError()
//NSFileHandle.fileHandleWithStandardInput()
//another class provided by Apple -> allows us to access NextConsole
//adding line breaks automatically
var input = NSString(data: standardInput.availableData, encoding: NSUTF8StringEncoding)
input = input!.stringByTrimmingCharactersInSet(NSCharacterSet.newlineCharacterSet())
//as ->
return input as! String
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment