0
Swift course
So is their just no standard user input for Swift 4?
4 ответов
+ 4
Use readLine() to get the input as a String Optional (String?). You can then unwrap and convert the string to the desired type.
+ 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.
+ 1
ChaoticDawg I googled and saw that and didn’t know how to “unwrap” the string
+ 1
var s : String = readLine()!
the exclamation mark make it 'unwrap' the string...
that also cause an error if no input is provided ^^