R.swift
R.swift copied to clipboard
Can't use fonts inside a Dynamic Framework
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?
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.
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 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)")
}