5

When compiling my project in the latest Xcode beta I get the following error.

enter image description here

The line of code that causes it is this:

let font = UIFont(name: "OpenSans-Semibold", size: 10.0)

I am not sure how to fix this.

Any idea?

So here's more context:

private lazy var view: UIView = {
        let view = UIView(frame: CGRectMake(0, 0, 34, 80))
        let label = UILabel()
        label.translatesAutoresizingMaskIntoConstraints = false
        let font = UIFont(name: "OpenSans-Semibold", size: 10.0)
        label.font = font
        return view
    }()
zumzum
  • 17,984
  • 26
  • 111
  • 172
  • 2
    Are you sure that's exactly the line of code? Can you show more context? – jtbandes Mar 07 '16 at 21:42
  • 2
    If that's really the line, then it looks like 7.3 beta has a bug. Please report a RADAR. Maybe changing to `let font: UIFont? = UIFont(name: "OpenSans-Semibold", size: 10.0)` would help. – Lou Franco Mar 07 '16 at 22:13
  • I think it's a bug in Xcode -- work around it by trying equivalent lines until you find one that works. – Lou Franco Mar 07 '16 at 22:19

1 Answers1

0

Yep I had this same problem too. Nothing worked for me until I tried initializing UIFont with UIFontDescriptor. So your code now would look like:

private lazy var view: UIView = {
    let view = UIView(frame: CGRectMake(0, 0, 34, 80))
    let label = UILabel()
    label.translatesAutoresizingMaskIntoConstraints = false
    let descriptor = UIFontDescriptor(name: "OpenSans-Semibold", size: 10.0)
    let font = UIFont(descriptor: descriptor, size: 10.0)
    label.font = font
    return view
}()

Also you might need to clean & rebuild your project after this change, the Xcode compiler didn't recognize the change at first.

Richard Ash
  • 362
  • 3
  • 6