+ 5
swift input
var a : String = readLine() // why this code causes error, why we must use optional like var a : String? = readLine()
2 odpowiedzi
+ 5
Okay so the problem is that using it as :
var a : String = readline()
will produce an error because the readLine function gives an optional.
Write it like this :
var a : String = readLine()!
The exclamation mark is important because it is used to forcefully unwrap the optional. That's wild also cause an error if no value is imputed, so he sure to put a value.
https://code.sololearn.com/cDU569xvCnss/?ref=app
+ 1
readLine() return “String?”(optional), so this is something about return type