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 trialAman Kumar
10,444 PointsHow does playlistImageView finds the index ?
How does the statement find the index that we can use in if let statement
let playlistImageView = sender?.view as! UIImageView
if let index = find(playlistsArray, playlistImageView) {
println(index)
playlistDetailController.playlist = PlaylistDictionary(index: index)
}
1 Answer
Tukang Keboen
2,840 Pointsxcode 7.0
let playlistImageView = sender!.view as! UIImageView
if let index = playlistsArray.indexOf(playlistImageView)
Chris Stromberg
Courses Plus Student 13,389 PointsChris Stromberg
Courses Plus Student 13,389 Pointsthe object returned is than cast as a UIImageView type and assigned to a constant named "playlistImageView".
if let index = find(playlistsArray, playlistImageView) is a built in function that uses two parameters sequence and element.
The sequence parameter looks at the playlistsArray and searches to see if your playlistImageView is within that sequence(array). If it does find that matching element, it returns the index number where that element resides.
This index number is now passed to our PlaylistDictionary(index: index) function and we assign the newly initialized object to the playlistDetailController property named playlist.