Give Int an initializer that takes a single Character

Oh, and by the way, you don't have to use map twice, this will work

let chars: [Character] = ["4", "④", "万", "a"]
let numbers = chars.compactMap(\.wholeNumberValue)
print(numbers) // [4, 4, 10000]
let numbersAndNils = chars.map(\.wholeNumberValue)
print(numbersAndNils) // [Optional(4), Optional(4), Optional(10000), nil]
1 Like