Reputation: 211
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.
Upvotes: 7
Views: 6715
Reputation: 771
class SecondViewController: UIViewController {
@IBOutlet weak var name: UILabel! = nil
override func viewDidLoad() {
super.viewDidLoad()
name.text="i m a label"
}
}
This code working fine
But when i replace @IBOutlet weak var name: UILabel? it is not working.
Upvotes: 0
Reputation: 14905
It should be like that (in Beta 3 or before):
@IBOutlet var button: UIButton?
IBOutlets must be optionals so place a ?
behind the type.
Upvotes: 12
Reputation: 2216
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
Upvotes: 11