When hooking Swift code up to a Storyboard, how do you add the IBAction
and IBOutlet
tags?
I would agree more with Jayprakash than the upvoted first answer. The only thing I would correct is the marking of the IBOutlets as implicitly unwrapped with the !
The first answer used to be correct, but several changes were made in Swift and how it interacts with IB in the latest release. In Swift, IBOutlets no longer have any implicit behavior or magic--they are simply annotations for IB. As of the date of this response, the following code is correct:
// How to specify an the equivalent of IBOutletCollection in Swift
@IBOutlet var fields: [UITextField]!
// How to specify a standard IBOutlet
@IBOutlet weak var button: UIButton!
// How to specify an IBAction
@IBAction func buttonWasPressed(sender: UIButton) { ... }