EarthDemon
EarthDemon

Reputation: 13

Unicode and Acceptable Arguments for "\u{}"

"\u{63}"
"\u{1FF}"
"\u{23E}"

all produce the desired result - various unicode characters, but I can't get the function to accept a variable. I have tried defining variable types including INT, UINT and UINT8 without success.

I have looked at documentation and all over. Any help appreciated.

Many thanks

Upvotes: 1

Views: 1287

Answers (1)

hennes
hennes

Reputation: 9342

If you want to do it dynamically, you can create Character instances from UnicodeScalar instances like this

Character(UnicodeScalar(0x63))  // c
Character(UnicodeScalar(0x1FF)) // ǿ
Character(UnicodeScalar(0x23E)) // Ⱦ

which could be easily wrapped into a function

func characterForUnicodeCodePoint(codePoint: UInt32) -> Character {
    return Character(UnicodeScalar(codePoint))
}

Upvotes: 2

Related Questions