swiftui-example icon indicating copy to clipboard operation
swiftui-example copied to clipboard

Optional to String

Open jaywcjlove opened this issue 4 years ago • 0 comments

func convertToInt(_ string: String?) -> Int? {
    return string.flatMap(Int.init)
}

let str = convertToInt("23")
print(str) // Optional(23)

print(str ?? "") // 23

guard let value = str else {return}
print(value) // 23

jaywcjlove avatar Apr 28 '21 02:04 jaywcjlove