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

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.