"Archiving error" when using a custom font

Hello ! 👋

I encountered an issue while using a custom font.
Because of multiple targets, I use a "Design System" framework that embed the needed fonts and register them if necessary using

Code Block objc
CTFontManagerRegisterGraphicsFont()


The fonts seemed to successfully register, and I try to display a simple text with a custom font such as

Code Block swift
Text(title.uppercased())
.font(.custom("SoleilW01-Light", size: 14))


But when running the Widget I encounter the log in console

[widget] [xxxx] archiving error

Have anyone encountered this issue ?

Thank you




Answered by johnbrayton in 631276022
I am seeing the same. FB8642825.
Accepted Answer
I am seeing the same. FB8642825.
Accepted Answer
FYI, I got this helpful response to my FB, and it worked for me. I hope it helps you as well:


You can’t use CTFontRegisterGraphicsFont() created from a CGDataProvider for widgets.

Instead you can use CTFontManagerRegisterFontsForURL() and it is much simpler than the code you attached:

Code Block
        let bundle = Bundle(for: MyFonts.self)
        let url = bundle.url(forResource: "miso-light", withExtension: "otf")!
        var error: Unmanaged<CFError>?
        if !CTFontManagerRegisterFontsForURL(url as CFURL, .process, &error) {
            print("unable to register font: \(error!.takeUnretainedValue())")
        } else {
            print("registered!")
        }



"Archiving error" when using a custom font
 
 
Q