title: How to get all characters of the font with CTFontCopyCharacterSet() in Swift?
body: <p>How does one get all characters of the font with <code>CTFontCopyCharacterSet()</code> in Swift? ... for macOS?</p>
  
  <p>The issue occured when implementing the approach from an <a href="https://stackoverflow.com/questions/18238804/osx-cgglyph-to-unichar/18239177#18239177">OSX: CGGlyph to UniChar</a> answer in Swift.</p>
  
  <pre class="lang-swift prettyprint-override"><code>func createUnicodeFontMap() {
      // Get all characters of the font with CTFontCopyCharacterSet().
      let cfCharacterSet: CFCharacterSet = CTFontCopyCharacterSet(ctFont)
  
      //    
      let cfCharacterSetStr = "\(cfCharacterSet)"
      print("CFCharacterSet: \(cfCharacterSet)")  
  
      // Map all Unicode characters to corresponding glyphs
      var unichars = [UniChar](…NYI…) // NYI: lacking unichars for CFCharacterSet
      var glyphs = [CGGlyph](repeating: 0, count: unichars.count)
      guard CTFontGetGlyphsForCharacters(
          ctFont, // font: CTFont
          &amp;unichars, // characters: UnsafePointer&lt;UniChar&gt;
          &amp;glyphs, // UnsafeMutablePointer&lt;CGGlyph&gt;
          unichars.count // count: CFIndex
          )
          else {
              return
      }
  
      // For each Unicode character and its glyph, 
      // store the mapping glyph -&gt; Unicode in a dictionary.
      // ... NYI
  }
  </code></pre>
  
  <p>What to do with <code>CFCharacterSet</code> to retrieve the actual characters has been elusive.  Autocompletion of the <code>cfCharacterSet</code> instance offers show no relavant methods.</p>
  
  <p><a href="https://i.stack.imgur.com/tr9w5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tr9w5.png" alt="enter image description here"></a></p>
  
  <p>And the <a href="https://developer.apple.com/documentation/corefoundation/cfcharacterset-rvm" rel="nofollow noreferrer">Core Foundation > CFCharacterSet</a> appears have methods for creating another CFCharacterSet, but not something the provides an array|list|string of unichars to be able to create a mapped dictionary.</p>
  
  <hr>
  
  <p>Note: I'm looking for a solution which is not specific to iOS as in <a href="https://stackoverflow.com/questions/41592139/get-all-available-characters-from-a-font">Get all available characters from a font</a> which uses <code>UIFont</code>.</p>