Today I Learned

A Hashrocket project

Emoji Variables in Swift #๐Ÿš€

Swift allows developers to specify variable names in unicode, which is very helpful if you and the rest of the developers to ever touch your code speak a non-english language which uses unicode characters:

let ไฝ ๅฅฝ = "ไฝ ๅฅฝไธ–็•Œ"

It is also useful if you want to specify special constants such as

let ฯ€ = 3.14159

most importantly though, it allows developers to use emojis for variable names:

let ๐Ÿถ๐Ÿฎ = "dogcow"
let ๏ผƒ๐Ÿš€ = "Hashrocket"
NSLog(๏ผƒ๐Ÿš€)

but donโ€™t take my word for it, read the official documentation which contains some of the above examples.

Note: the pound sign above (๏ผƒ) is unicode, that is why it is allowed as part of a variable name, whereas normal # sign is not.

P.S. to access emojis and other unicode symbols directly in the current edit field press ^โŒ˜+\ on Mac.