Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input from the keyboard in command line application

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?

like image 457
Chalkers Avatar asked Jun 02 '14 23:06

Chalkers


People also ask

How to take input from command in Python?

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.

How to take user input from Terminal in Python?

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().

How do you ask for user input in Swift?

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.


1 Answers

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.

like image 171
Ezekiel Avatar answered Nov 15 '22 18:11

Ezekiel