<div dir="ltr"><div>I want a function f such that:</div><div><br></div><div>f(&quot;abc&quot;) == [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]</div><div><br></div><div>f(&quot;cafรฉ&quot;) == [&quot;c&quot;, &quot;a&quot;, &quot;f&quot;, &quot;รฉ&quot;]</div><div><br></div><div>f(&quot;๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ๐Ÿ‘ท๐Ÿพโ€โ™€๏ธ&quot;) == [&quot;๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ&quot;, &quot;๐Ÿ‘ท๐Ÿพโ€โ™€๏ธ&quot;]</div><div><br></div><div>I&#39;m not sure if the last example renders correctly by mail for everyone but the input String contains these _two_ &quot;natural/visual characters&quot;:</div><div>(1) A family emoji</div><div>(2) a construction worker (woman, with skin tone modifier) emoji.</div><div>and the result is an Array of two strings (one for each emoji).</div><div><br></div><div>The first two examples are easy, the third example is the tricky one.</div><div><br></div><div><div>Is there a (practical) way to do this (in Swift 3)?</div></div><div><br></div><div>/Jens</div><div><br></div><div><br></div><div><br></div><div>PS</div><div><br></div><div>It&#39;s OK if the function has to depend on eg a graphics context etc.</div><div>(I tried writing a function so that it extracts the glyphs, using NSTextStorage, NSLayoutManager and the AppleColorEmoji font, but it says that &quot;๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ๐Ÿ‘ท๐Ÿพโ€โ™€๏ธ&quot; contains 18(!) glyphs, whereas eg &quot;cafรฉ&quot; contains 4 as expected.)</div><div><br></div><div><div>If the emojis of the third example doesn&#39;t look like they should in this mail, here is another way to write the exact same example using only simple text:</div><div><br></div><div>let inputOfThirdExample = &quot;\u{1F468}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}\u{1F477}\u{1F3FE}\u{200D}\u{2640}\u{FE0F}&quot;<br></div><div><br></div><div>let result = f(inputOfThirdExample)</div><div><div><br></div><div>let expectedResult = [&quot;\u{1F468}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}&quot;, &quot;\u{1F477}\u{1F3FE}\u{200D}\u{2640}\u{FE0F}&quot;]</div><div><br></div><div>print(result.elementsEqual(result)) // Should print true<br></div></div></div><div><br></div><div><br></div></div>