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

Shay Paustovsky
Shay Paustovsky
969 Points

@IBAction methods with or without parameters ?

Hello,

I was wondering if someone could explain this bit of code :

'''swift @IBAction func sliderMoved(_ slider: UISlider) { print("The value of the slider now is: (slider.value)") }

''' And why do we have a parameter between the parenthesis and if we can remove it and if yes would it make a difference.

Thanks in advance.

Shay

1 Answer

Chris Stromberg
PLUS
Chris Stromberg
Courses Plus Student 13,389 Points

It may help to read up on UIControl and the paragraph titled "The Target-Action Mechanism".

https://developer.apple.com/documentation/uikit/uicontrol

To summarize, you could have more than one interface item connected to your action/method. The sender parameter specifies what object sent the message, or what button was pressed, if more than one button was connected to your action.