0
how can i call for a user input in swift?
I was trying to program in swift through a windows swift compiler and was researching how can i call the user to input a data. I tried to use readLine() but if i use this function without a if condition, it return a optional value, but if i use the if condition, i cant call for the input value out of the condition the code: if let str = readLine() { print("Hello \(str), welcome to my code!") } print(str) the error: E:\IOS\SWIFT\docs\print.swift:8:7: error: use of unresolved identifier 'str' print(str)
1 Odpowiedź
+ 2
If it giving you optional condition in output then use this syntax instead.
let str = readLine()
print("your name = \(str!)")