What
If you're not familiar with the isEmoji instance property it's a boolean value indicating whether the scalar has an emoji presentation, and whether or not it is the default.
It's available under iOS 10.2+, iPadOS 10.2+, macOS 10.12.2+, Mac Catalyst 10.2+, tvOS 10.1+, watchOS 3.1.1+, visionOS 1.0+ Beta.
I did a little research after facing this issue and found the answer in Apple's documentation.
Why
The final result is true because the ASCII digits have non-default emoji presentations; some platforms render these with an alternate appearance.
Because of this behavior, testing isEmoji alone on a single scalar is insufficient to determine if a unit of text is rendered as an emoji; a correct test requires inspecting multiple
scalars in a Character.
In addition to checking whether the base scalar has isEmoji == true, you must also check its default presentation (see isEmojiPresentation) and determine whether it is followed by a variation selector that would modify the presentation. This property corresponds to the βEmojiβ property in the Unicode Standard.
Solution
So you can check like the line below:
let scalars: [Unicode.Scalar] = ["π€", "+", "1"]
for s in scalars {
print(s, "-->", (s.properties.isEmoji && s.properties.isEmojiPresentation))
}
Final Results
// π€ --> true
// + --> false
// 1 --> false
π
"βοΈ"
which returns true forisEmoji
and false forisEmojiPresentation
β Electrotonus