title: Swift, Extracting Glyphs from a Font by Name
body: <p>I am attempting to glyphs from the SF Symbol front using the code sample below provided by an extract <a href="https://github.com/davedelong/sfsymbols" rel="nofollow noreferrer">https://github.com/davedelong/sfsymbols</a>. I have isolated the code that I can't get to work with values extracted from a run time.</p>
  
  <p>I have condensed the code down to only the statements required to produce the problem. </p>
  
  <p>This issue seems to be the name I am providing to the final statement in CTFontGetGlyphWithName, Every combination of values I have attempted returns 0.</p>
  
  <p>Please note that you have to have the SF Symbols application installed for it to acquire the initial bundle.</p>
  
  <p>Please excuse the code quality, this is just to create the shortest possible example of code to reproduce the problem.</p>
  
  <p>thanks.</p>
  
  <p>I have followed quite a few snipped and tutorials but there doesn't seem to be a great deal of practical examples of these more advanced functions available.</p>
  
  <pre><code>public class StackOverflow {
  
      public func Test() {
          let maybeCFURLs = LSCopyApplicationURLsForBundleIdentifier("com.apple.SFSymbols" as CFString, nil)?.takeRetainedValue()
  
          let cfURLs = maybeCFURLs as? Array&lt;URL&gt;
  
          let fontFile = cfURLs!.compactMap { url -&gt; URL? in
              guard let appBundle = Bundle(url: url) else { return nil }
              return appBundle.url(forResource: "SFSymbolsFallback", withExtension: "ttf")
          }
  
          let attributes = [
              kCTFontTraitsAttribute: [
                  kCTFontWeightTrait: NSFont.Weight.regular.rawValue
              ]
          ]
  
          let provider = CGDataProvider(url: fontFile.first! as CFURL)
          let cgFont = CGFont(provider!)
  
          let ctAttributes = CTFontDescriptorCreateWithAttributes(attributes as CFDictionary)
          let font = CTFontCreateWithGraphicsFont(cgFont!, 32, nil, ctAttributes)
  
          // let name = "uni.plus.square.fill.medium" as CFString - Does not work
          //var name = "square.fill.medium" as CFString - Does not work
          let glyphName = "plus.square.fill.medium" as CFString
  
          var glyph = CTFontGetGlyphWithName(font, glyphName )
      }
  }
  </code></pre>