0

My question is

How can I use Regional Flag ex) Flag of Califonia (regional flag)

Some regional flag of apple keyboard existed can be used (gbeng, gbzet, gbwls ...)

I have used unicode sequence like this

let califonia = "\u{1F3F3}\u{E0075}\u{E0073}\u{E0063}\u{E0061}\u{E007F}"
print(califonia) // 🏳

according these links

but it's always show white flag like this 🏳

Is there a way to use flag of Regional flag?

My example source tested in Swift 4.1 with iPhone X (iOS 11.4)

2
  • @MartinR: that's not quite correct. Since Swift 4.0, Swift uses the ICU library of the OS the code is running on. So programs will automatically "learn" new Unicode rules as OSes get updated. Aug 13, 2018 at 18:29
  • @OleBegemann: OK, thanks.
    – Martin R
    Aug 13, 2018 at 18:30

2 Answers 2

2

Since Swift 4.0, Swift uses the Unicode library (ICU) of the OS the code is running on. So Swift essentially has the same knowledge of Unicode as the underlying OS.

I just tested this on macOS 10.13.6 and both Swift 4.1 (Xcode 9.4) and 4.2 (Xcode 10.5) handle the regional flag emoji correctly. That is, it's recognized as a single Character:

let california = "\u{1F3F3}\u{E0075}\u{E0073}\u{E0063}\u{E0061}\u{E007F}"
california.count // returns 1 in Swift 4.1 on macOS 10.13.6

Now Swift has nothing whatsoever to do with how this emoji is rendered, i.e. if your OS ships with a font that includes a glyph for the flag of California. This will vary from OS to OS and current Apple OSes don't seem to include a glyph (the flag also appears white on iOS 12 beta 6 in my tests). But again, this has nothing to do with Swift.

2

There's not a Swift problem here, but one with the underlying OS / platform and font support.

let california = "🏳\u{E0075}\u{E0073}\u{E0063}\u{E0061}\u{E007F}"
california.count // .characters not needed / deprecated in Swift 4

This correctly returns 1 — according to Swift's string processing system, you have a single emoji character here.

However, just because Swift sees it as a single character per the Unicode 10.0 / Emoji 5.0 spec doesn't mean that whatever platform you're running on knows how to display that character. Whether you see the correct flag image for any given tag sequence depends on whether the platform and font you're viewing that sequence with includes an image/glyph for that tag sequence.

The AppleColorEmoji font included with macOS, iOS, and other Apple platforms includes glyphs for some of the regional/subdivision flag tag sequences defined by that spec, not every possible ISO 3166-2 region. Specifically, the font includes only those three region tags called out in the Unicode 10.0 / Emoji 5.0 spec as Recommended for General Interchange (as noted in the pages your question links to): 🏴󠁧󠁢󠁥󠁮󠁧󠁿England, 🏴󠁧󠁢󠁳󠁣󠁴󠁿Scotland, and 🏴󠁧󠁢󠁷󠁬󠁳󠁿Wales.

A platform/font vendor such as Apple or Twitter is allowed to provide font glyphs/images for other ISO 3166-2 region tag sequences. (But the spec doesn't require one to provide such in order to claim compliance, so most vendors don't.) In Apple's case, you can at least file bugs to request support for more... perhaps they could be talked into supporting California so that the fine print on every Mac can say something like "👩‍🎨 by  in 🏳󠁵󠁳󠁣󠁡󠁿"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.