'hello, I need to return an integer type for a string place, but due to lack of knowledge, I ran into a wall

private func vvodAge() ->Int{
    var vvod:String? = readLine()
    if ((vvod == nil)){vvod = "0"}
   return Int(vvod)
}

//i just need to input a string check it and output int



Solution 1:[1]

try the below.

func vvodAge() -> Int {
    var vvod:String? = readLine()
    if ((vvod == nil)){vvod = "0"}
   return Int(vvod!)!
}
print(vvodAge())

then type command like this.

#swiftc foo.swift
#echo "100" | ./foo // => 100

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tana005