Tim Dietrich

Custom Software Developer

Home Services Portfolio Blog About Contact Newsletter

Swift: Working With Unicode Characters

I stumbled upon this tip today while working in Swift.

You can easily specify a Unicode character with the following syntax:

\u{n}

"n" is the 1-to-8 digit hexadecimal number that represents the character's code point. A helpful list of Unicode characters and their code points is available here.

For example, to print a trademark symbol:

print("\u{2122}")

Similarly, you can print the Apple logo:

print("\u{F8FF}")

A screenshot of a Swift playground showing a few Unicode characters is included below. (Click the image to see a larger version.)


You can learn more about Swift's Unicode support in the Swift Programming Language library,