Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does NSObject.BroadSystemFontWeights warning message mean?

I recently updated XCode to 7.0 and I get this warning message:

 Xcode.IDEInterfaceBuilder.Cocoa.NSObject.BroadSystemFontWeights

enter image description here

What does it mean and how do I get rid of it ?

like image 643
anto0522 Avatar asked Sep 24 '15 17:09

anto0522


2 Answers

I got the same error when I set the font weight to Semibold to a label with system font. This weight is available for the new system font (San Francisco) but not for the old Helvetica Neue, so I guess that that error means we won't get the right weight on older OS.

Changing the font to a weight available also for Helvetica Neue, Bold in my case, has fixed the error for me.

like image 92
Marco Boschi Avatar answered Nov 17 '22 15:11

Marco Boschi


The problem is not with changing system font weight, the problem is with Xcode not handling this properly – contradicting statement, I know, see full blog post for details. There are three scenarios.

First – explicit typography is not important, regular weight is acceptable. Then stick with Marco's answer and use explicit regular weight.


Second – explicit typography is preferable, but can be compromised on older systems. This is the default behaviour right now, Xcode simply shows a warning and uses regular font on pre-10.11 targets. If you use adaptive layouts, everything should be fine. To get rid of the warning, you can simply set higher target in storyboard inspector:

Note, if your storyboard uses fallback features for earlier targets, they might become disabled, which will cause problems – I haven't come across any so far.


Third – explicit typography is a must. In this case you can use custom textfield with custom inspectable property. Open up identity inspector and set custom class to TextField, preferred font weight attribute will show up in attribute inspector, set the required value, build and enjoy the result.

import AppKit

@IBDesignable public class TextField: NSTextField
{
    @IBInspectable public var preferredFontWeight: Int = 0

    override public func awakeFromNib() {
        if #available(OSX 10.11, *) {
            return
        }

        guard
        let weight: Int = self.preferredFontWeight where weight > 0,
        let font: NSFont = self.font,
        let name: String = font.familyName,
        let manager: NSFontManager = NSFontManager.sharedFontManager() else {
            return
        }

        // Full details here – https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSFontManager_Class/#//apple_ref/occ/instm/NSFontManager/convertWeight:ofFont:   
        //
        // 1 – ultralight
        // 2 – thin
        // 3 – light, extralight
        // 4 – book
        // 5 – regular, display
        // 6 – medium
        // 7 – demi, demibold
        // 8 – semi, semibold
        // 9 – bold
        // 10 – extra, extrabold
        // 11 – heavy
        // 12 – black
        // 13 – ultrablack
        // 14 – extrablack

        if let font: NSFont = manager.fontWithFamily(name, traits: manager.traitsOfFont(font), weight: weight, size: font.pointSize) {
            self.font = font
        }
    }
}

P.S. Bold weight works probably because it uses a slightly different logic – there's boldSystemFontOfSize(_:) that's available since OS X 10.0, unlike many other methods, which storyboard might rely upon.

like image 2
Ian Bytchek Avatar answered Nov 17 '22 14:11

Ian Bytchek