-1

This is my code:

override func viewDidLoad() {
    super.viewDidLoad()

    var label89val: LTMorphingLabel!
    label89val = LTMorphingLabel(frame: CGRectMake(20, 10, 80, 80))
    label89val.delegate = self
    label89val.morphingEffect = .Scale
    label89val.text = "0"
    label89val.textColor = UIColor.whiteColor()
    label89val.font = UIFont.boldSystemFontOfSize(23)
    label89val.setNeedsDisplay()
    self.view.addSubview(label89val)

It crashes at:

label89val.text = "0"

and shows this error:

fatal error: unexpectedly found nil while unwrapping an Optional value

Moon Cat
  • 1,941
  • 3
  • 18
  • 25
Jason Zhao
  • 1,278
  • 4
  • 18
  • 36

2 Answers2

-1

I had the same thing here and for me the solution was as follows.

Every now and than I put my own variables and expressions into the debugging area to see right away if their values are correct. Some of those expressions had "unvalid expression" as result. Removing all of these "unvalid expression" solved the problem. The error doesn´t come up anymore.

Hope this helps

Ronald Hofmann
  • 1,342
  • 2
  • 15
  • 26
-1

Try this:

override func viewDidLoad() {
    super.viewDidLoad()


    if let label89val = LTMorphingLabel(frame: CGRectMake(20, 10, 80, 80)) {
       label89val.delegate = self
       label89val.morphingEffect = .Scale
       label89val.text = "0"
       label89val.textColor = UIColor.whiteColor()
       label89val.font = UIFont.boldSystemFontOfSize(23)
       label89val.setNeedsDisplay()
       self.view.addSubview(label89val?)
    }
}
D4ttatraya
  • 3,236
  • 1
  • 26
  • 47