To read standard input in swift we will need to use readLine() function.
Function
readLine(strippingNewline:)
Returns a string read from standard input through the end of the current line or until EOF is reached.
Declaration
func readLine(strippingNewline: Bool = true) -> String?
Reading String
let string_input = readLine()
if let string_input = string_input {
print(string_input)
}
Reading Int
let number_input = Int(readLine()!)
if let number_input = number_input {
print(number_input)
}
Reading Float
let number_input = Float(readLine()!)
if let number_input = number_input {
print(number_input)
}
functions input readLine