SWIFT

[Swift] Character를 Int로 변환

clamp 2023. 1. 2. 15:44
let char: Character = "5"
if let intValue = char.wholeNumberValue{
    print(intValue)
} else { 
    print("Not an Integer")
}


또는
let char: Chracter = "1"
if let number = Int(String(char)){
    //use number
}

속도는 .wholeNumberValue가 더 빠르다고 한다.