+ 1

Why doesn't this work in Swift?

Here's the code: var ☆ = 56 print(☆) Why doesn't this work even though Swift supports unicode characters? According to me, I haven't violated any variable-naming rules.

23rd Jul 2021, 10:48 AM
Calvin Thomas
Calvin Thomas - avatar
2 Answers
+ 11
https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//apple_ref/doc/uid/TP40014097-CH30-ID412 Under "Identifiers": "...Identifiers begin with an uppercase or lowercase letter A through Z, an underscore (_), a noncombining alphanumeric Unicode character in the Basic Multilingual Plane, or a character outside the Basic Multilingual Plane that isn’t in a Private Use Area. After the first character, digits and combining Unicode characters are also allowed... " The hollow star you used, if I'm not mistaken, is U+2606. This appears to lie outside the accepted range of unicode starting U+20xx to U+27xx. identifier-head → U+2070–U+20CF, U+2100–U+218F, U+2460–U+24FF, or U+2776–U+2793
23rd Jul 2021, 11:41 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Hatsy Rei Thank you very much.
23rd Jul 2021, 11:48 AM
Calvin Thomas
Calvin Thomas - avatar