Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i find the source of this font-related coretext warning in IOS13?

Working on an update of my app i notice that i get tons of warnings in the log when running the app in Xcode 11.2 on IOS13.

CoreText note: Client requested name ".SFUI-Regular", it will get TimesNewRomanPSMT rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[UIFont systemFontOfSize:].

I dug around a bit and found this quote from WWDC:

As mentioned in numerous WWDC sessions, dot-prefixed font names are not to be directly used.

I am myself almost exclusively using IB and nibs to set fonts for textfields etc., and there is no reference to "SFUI-Regular" in my code anywhere, so i am not sure how to find the actual reason for these warnings (i have something like 20-30 rows of these in the logs).

Does anyone have any tips on how i can find where the warning comes from, and how to fix it?

like image 664
Mathias Avatar asked Nov 05 '19 07:11

Mathias


4 Answers

There is another output in console, you can try to add a symbolic breakpoint

CoreText note: Set a breakpoint on CTFontLogSystemFontNameRequest to debug.

like image 145
clatt Avatar answered Nov 15 '22 07:11

clatt


I started experiencing this warning in the console starting with Xcode 11, with both MacOS and iOS targets.

You will receive ".SFUI-Regular" from UIFont.systemFont(ofSize: X).fontName. The warning will then occur if you try to instantiate using UIFont(name: fontName, size: size).

In my case I am letting the user customize the display font, but the default was ".SFUI-Regular", so I have changed that to "TimesNewRomanPSMT"

let defaultFont = UIFont.systemFont(ofSize: X).fontName

// replace with
let defaultFont = "TimesNewRomanPSMT"

UIFont(name: defaultFont, size: size)
like image 45
gheclipse Avatar answered Nov 15 '22 05:11

gheclipse


Having the same issue and no reference to dot-prefixed font in my code either. Set a symbolic breakpoint but nothing of any use

like image 25
Tony Law Avatar answered Nov 15 '22 07:11

Tony Law


I got this if I blindly used:

UIFont(name: fontName, size: fontSize)

and the fontName was "System Font", which was part of a list I got from:

let fontFamilyNames = UIFont.familyNames.sorted()

Workaround was to check the name.

let isSystemFont = fontName == "System Font"
let useFont = isSystemFont ? UIFont.systemFont(ofSize: fontSize) : UIFont(name: fontName, size: fontSize) ?? UIFont.systemFont(ofSize: fontSize)
like image 44
anorskdev Avatar answered Nov 15 '22 07:11

anorskdev