R.swift icon indicating copy to clipboard operation
R.swift copied to clipboard

Can't use fonts inside a Dynamic Framework

Open charleslima opened this issue 4 years ago • 3 comments

I have a dynamic framework that is intent to contains all the strings and fonts to be shared for project's modules. The problem is that when I run the main target and call the MyDynamicFramework.R.font.myCustomFont() it returns nil. Is there a way to solve this?

charleslima avatar Mar 24 '20 22:03 charleslima

I have the same problem. It appears that the calls don't actually use the hostingBundle. Actually it's normal, you need custom code to load a font dynamically from a location. I found a workaround by modifying the app plist UIAppFonts to point to the fonts in the dynamic framework as described here.

c0diq avatar Apr 16 '20 07:04 c0diq

I don't have experiences with using fonts from a framework.

@charleslima Does the solution by @c0diq work for you as well?

If so it seems this is just normal Xcode behaviour. In that case we perhaps should add this to the documentation, but I'm not sure what else to do.

tomlokhorst avatar Apr 22 '20 14:04 tomlokhorst

@tomlokhorst The @c0diq solution worked for me. I also was able to fix it by registering the fonts manually inside my dynamic framework with the following code:

if let cfURL = bundle.url(forResource: fontName, withExtension: "ttf") {
      CTFontManagerRegisterFontsForURL(cfURL as CFURL, .process, nil)
} else if let cfURL = bundle.url(forResource: fontName, withExtension: "otf") {
      CTFontManagerRegisterFontsForURL(cfURL as CFURL, .process, nil)
} else {
      assertionFailure("Could not find font:\(fontName) in bundle:\(bundle)")
}

charleslima avatar Apr 30 '20 16:04 charleslima