iOS

Robert Vazquez
Robert Vazquez
1,782 Points

what is the difference between IBOutlet and IBActions in Xcode with Swift

I am starting out to use Xcode with Swift but I am suck when they are talking about using IBOutlet and IBActions in Xcode BUT I don't understand the difference between the two. please help

2 Answers

Richard Lu
Richard Lu
20,185 Points

Hey Robert,

IBOutlets are used for referencing something that's on the storyboard. Let's say there's a button on the storyboard that needs to be access in the code, you can control drag it onto the associated viewcontroller class file.

@IBOutlet weak var aButton: UIButton!

the button can now be manipulated in that class file

aButton.currentTitle = "I've change the buttons title"

IBActions are used for "actions", what happens when i click on this button?

@IBAction func buttonPressed(sender: AnyObject) {
   print("HEY! I'VE PRESSED THE BUTTON")
}

Hope I've helped. Happy Coding! :)

Robert Vazquez
Robert Vazquez
1,782 Points

yes Thanks for helping me out with this in Xcode Thanks a lot Richard

Richard Lu
Richard Lu
20,185 Points

Anytime Robert, I'm always looking to help! :)