+ 2

How to take user input in swift?

10th Dec 2016, 5:16 AM
Gaurav Gupta
Gaurav Gupta - avatar
6 Respuestas
+ 2
use readLine, from the Swift Standard Library. https://developer.apple.com/reference/swift/1641199-readline Example: let response = readLine(strippingNewline: true) Will give you an Optional value containing the entered text.
10th Dec 2016, 6:28 AM
Kirk Seeger
Kirk Seeger - avatar
+ 1
Did you meant taking user input from a text field ?
21st Dec 2016, 6:31 PM
Alen Alexander
Alen Alexander - avatar
+ 1
1. You need to map your textfield property from storyboard or xib to its corresponding class file. 2. In class file, 'yourTextFieldName.text' will provide you the value entered by the user.
21st Dec 2016, 6:35 PM
Alen Alexander
Alen Alexander - avatar
0
yup
21st Dec 2016, 6:34 PM
Gaurav Gupta
Gaurav Gupta - avatar
0
var name = readLine()
5th Jan 2018, 7:10 PM
Joseph
0
will give you input stored inside of a variable called name.
5th Jan 2018, 7:11 PM
Joseph