Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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! :)