I am attempting to get the keyboard input for a command line app for the new Apple programming language Swift.
I've scanned the docs to no avail.
import Foundation println("What is your name?") ???
Any ideas?
The command line arguments must be given whenever we want to give the input before the start of the script, while on the other hand, raw_input() is used to get the input while the python program / script is running.
The Python Console accepts command in Python which you write after the prompt. User enters the values in the Console and that value is then used in the program as it was required. To take input from the user we make use of a built-in function input().
Getting input from the user in Swift is very easy with the help of the readLine() function. This function returns a string of characters which is read from the standard input at the end of the current line.
The correct way to do this is to use readLine
, from the Swift Standard Library.
Example:
let response = readLine()
Will give you an Optional value containing the entered text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With