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 Refactoring Our Code Tapping On Our Playlists

Mohsen Lotfi
Mohsen Lotfi
2,694 Points

I dont understand what sender does in gesture recognizer

I know in prepareForSegue method we used an Array to iterate between different playlists, but can't really understand what the gesture recogniser passes to tho prepareForSeguage so that it understand different inputs (playlists)

    @IBAction func showPlaylistDetail(sender: AnyObject) {       performSegueWithIdentifier("showPlaylistDetailSegue", sender: sender)}

I am sure it has something to do with sender but can't link it to any part of the code.

2 Answers

Martin Shay
Martin Shay
5,919 Points

the "sender" is the object that the user interacted with. the functions pass the "sender" along so you can make decisions in code depending on what object the gesture interacted with.

@soojin has a good answer but i am trying to be very concise.

Soojin Ro
Soojin Ro
13,331 Points

The sender of IBAction is the UIImageView that was tapped, so you get different senders for different imageviews tap. And you send that UIImageView as a parameter for performSegueWithIdentifier so you can access that imageview in prepareForSegue method in order to determine which imageview was tapped. You can hand over correct Playlist struct ONLY if you know which imageview was tapped.