josmek josmek - 5 months ago 18
iOS Question

'IBOutlet' property has non-optional type 'UIButton'

Here's my code:

import UIKit

class ViewController: UIViewController {

@IBOutlet var button: UIButton

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

}


It's a simple IBOutlet (straight from the Apple developer docs). It gives me the error "'IBOutlet' property has non-optional type 'UIButton'" and I have no idea how to fix it.

Avi Avi
Answer

It can also be-

    @IBOutlet var button: UIButton! 

or

    @IBOutlet var weak button: UIButton! (in case you are not doing view unloading)

if you are using XCODE 6 Beta 4

Comments