When hooking Swift code up to a Storyboard, how do you add the IBAction
and IBOutlet
tags?
Interface Builder The first is an editor, where you write the Swift code that makes your application run. The second is Interface Builder, which is the part where you lay out the graphical interface of your program—the buttons, toolbars, menus, images, and text that make up how your users interact with your program.
Conclusion. After looking at the pros and cons of both Storyboard and SwiftUI, according to my opinion building app UI using storyboard is comparatively easier for a beginner, and has been there was a very long time, but there are some flaws with it and that flaws have been taken care of in Swift UI.
Add IBAction
and IBOutlet
attributes to variables and functions so they can be visible in Interface builder.
class ViewController: UIViewController {
@IBOutlet var label: UILabel?
@IBAction func doTap(x:UIButton) {
println("Tapped: \(x)")
}
}
Below code shows IBOutlet and IBAction format in Swift :
class MyViewController: UIViewController {
@IBOutlet weak var btnSomeButton: UIButton?
@IBOutlet weak var lblLabelItem: UILabel?
@IBAction func btnSomeButtonClicked(sender: UIButton) {
...
}
}
You can bind them same way as done in Objective-C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With