0

Swift course

So is their just no standard user input for Swift 4?

30th May 2021, 6:30 AM
Roderick Davis
Roderick Davis - avatar
4 odpowiedzi
+ 4
Use readLine() to get the input as a String Optional (String?). You can then unwrap and convert the string to the desired type.
30th May 2021, 6:58 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
visph FYI, in the particular case of using readLine()! with the stdin it actually won't result in an error, because it will be equal to an empty String "", but in other cases it may, so better to safeguard your code appropriately. var s: String = readLine()! print(s=="") outputs true when you don't enter any value.
30th May 2021, 8:27 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
ChaoticDawg I googled and saw that and didn’t know how to “unwrap” the string
30th May 2021, 8:09 AM
Roderick Davis
Roderick Davis - avatar
+ 1
var s : String = readLine()! the exclamation mark make it 'unwrap' the string... that also cause an error if no input is provided ^^
30th May 2021, 8:18 AM
visph
visph - avatar