Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Simple iPhone App with Swift Views and View Controllers View Controllers and IBAction

what is the difference between outlet and action and when do we use each one for a button/label

Thanks in advance

1 Answer

Hey mark so the difference between an IBOUTLET and action is the IBOUTLET allows you to change properties of a control while the action is used for an event to trigger code basically do something. So you would only use an IBOUTLET when you wanted to change the way something looked i.e the Label you use an outlet since you want to change it's text property you could change it's size, colour, font etc but you would need to turn this into an outlet before you could do this on the other hand you would use an action when you want something to be triggered when the user presses something which in this case is changing the text in the label when you press the button you are using the action to activate a trigger event what this then does is it uses the IBOUTLET you declared before and changes the text property with the value returned from the method. Basically the action is used when you want the app to do something and the IBOUTLET is used when you want to change the properties of a control which is on display on the screen.

thank you so much