'UIFont' is not convertible to 'UIFont?'

后端 未结 3 832
花落未央
花落未央 2020-12-08 18:38

So I had updated my XCode to 7.3 today evening.

In one of my projects, I get the following error for few labels where I set the font:

\'(name: String         


        
相关标签:
3条回答
  • 2020-12-08 19:38

    I had this problem as well. What fixed it for me was to turn off Whole Module Optimization.

    Bulid Settings > Swift Compiler - Code Generation > Optimization Level

    I had set it to Fastest (Whole Module Optimization). When I set it to None I didn't have this problem anymore. For context, this is a mixed code base with both Objective-C and Swift.

    0 讨论(0)
  • 2020-12-08 19:43

    I had the same issue and doing this allows me to compile again:

    let descriptor = UIFontDescriptor(name: "OpenSans-Semibold", size: 10.0)
    label.font = UIFont(descriptor: descriptor, size: 10.0)
    

    So, use the UIFontDescriptor ...

    Also doing this works for me:

    if let font = UIFont(name: "OpenSans-Semibold", size: 10) {
        label.font = font
    }
    
    0 讨论(0)
  • 2020-12-08 19:45

    Elsewhere on SO, someone suggest that where you have this:

    aTitleView.font = UIFont(name: "Roboto-Regular", size: 15)
    

    ...you should try writing this:

    aTitleView.font = UIFont.init(name: "Roboto-Regular", size: 15)
    

    I can take no credit for this (because I can't reproduce the bug) so I'm just guessing! But it would be very interesting to know if it actually works.

    0 讨论(0)
提交回复
热议问题