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 trialArjun Amin
2,228 PointsIn an IBAction what is 'Sender' and 'AnyObject'?
what do the sender refer to in our view or anywhere in the code?
1 Answer
Sebastien Thomas
16,502 PointsHi Arjun,
The sender
is the object that called the action.
So let's say if you have 2 UIButtons calling the same function buttonPressed
. You can then use the sender
parameter to find out, using tags, which button was pressed for example :
@IBAction func buttonPressed(sender: AnyObject) {
let button = sender as UIButton
println("Button \(button.tag) was pressed!")
}
Hope this helps
Arjun Amin
2,228 PointsArjun Amin
2,228 Pointsthanks sebastian