Swift error: cannot convert value of type 'Int32' to expected type of argument 'Int32'

I am trying to write a couple of functions to convert a Stringto an array of bytes [UInt8]and vice versa.

As part of the function coming from [UInt8] -> String, I'm trying to convert one Int32to Character.

let num : Int32 = 5
let char = Character(_builtinUnicodeScalarLiteral: num)

But I get this strange error:

error: cannot convert value of type 'Int32' to expected argument type 'Int32'
let char = Character(_builtinUnicodeScalarLiteral: num)
                                                   ^~~

EDIT: I was able to write my functions using different code, but I'm still curious about the meaning of the error.

+4
source share
2 answers

you can use this constructor this way

let num: Int32 = 5
let g = Character(_builtinUnicodeScalarLiteral: num.value)
0
source

, _, . - builtin .

Character a UnicodeScalar, a UInt32 ( UInt8):

let num : UInt32 = 65
let g = Character(UnicodeScalar(num))
print(g) // prints 'A'

, Int32, Swift Builtin.Int32, . .

+1

Source: https://habr.com/ru/post/1617851/


All Articles