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 Playlist Browser with Swift Working With Multiple View Controllers Recap of iOS Basics

alahab2
alahab2
9,709 Points

UIButton Arguments when creating an IBAction

When we create an IBAction for a button there is a dropdown menu "Arguments": -None -Sender -Sender and Event

Can anyone describe the difference and give examples of their usage?

Thanks in advance.

1 Answer

Jeroen de Vrind
Jeroen de Vrind
29,772 Points

You just need to add arguments when you want something to do with it in the method you call when you press the button. Most of the time you don't need arguments and you can set it to 'None'.

In case different buttons call the same method and you wants to know which button did call the method, then you want to use the 'sender'. Sender is the object (in this case the button) that called the method. Or if you want to change or do something with the sender (button), you use sender.

The same for 'event'. If you want to distinct different events (like one tap, double tap) you can refer to this action in your code by using this event parameter.