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 trialWaseef Akhtar
Full Stack JavaScript Techdegree Student 2,802 Pointsfind() is no more supported with Swift 2.0.
I've been practicing this course with Swift 2.0 and everything just worked perfectly up until now. I'm trying to create the find() function but it's not available in the Xcode Version 7.0 Beta 3.
Please help if there's a similar solution to this problem.
8 Answers
Sasha Kiselev
2,382 PointsAfter googling for hours I have found how to retrive the index of an array element in Swift 2.0 from this stackoverflow http://stackoverflow.com/questions/24028860/how-to-find-index-of-list-item-in-apples-swift here is how to use it if let index = playlistArray.indexOf(playlistImageView) then function is indexOf which is a method of all arrays searching for ImageView. I can confirm it works
Nathan Tallack
22,160 PointsZOMG! I lub jooo!!! :)
David Maybach
2,092 Pointslet playlistImageView = sender!.view as! UIImageView
if let index = playlistArray.indexOf(playlistImageView) {
let playlistDetailController = segue.destinationViewController as! PlaylistDetailViewController
playlistDetailController.playlist = Playlist(index: index)
}
I couldn't get it to work. Not sure what you meant by "then func is indexOF
Denys Voloshyn
3,721 PointsThank You, it works!!:)
Sasha Kiselev
2,382 Pointsthe code i used is let playlistImageView = sender!.view as! UIImageView if let index = playlistArray.indexOf(playlistImageView) { let playlistDetailController = segue.destinationViewController as! PlaylistDetailViewController playlistDetailController.playlist = Playlist(index: index) } are you sure you are using the latest xcode 7 version?
Lydia Khashina
3,015 PointsSasha, I used your code but I've run into an error '[UIImageView]' does not have a member named 'indexOf' in the line:
if let index = playlistArray.indexOf(playlistImageView) {}
Could you please help me? :)
P.S. Are you from Russia? :)
michael de marigny
3,411 PointsThanks Sasha, works perfect with version 7 beta 4
Sasha Kiselev
2,382 PointsI am from Russia, the problem you might have is that you are using a different version of XCode, the version in which this code works is the XCode 7 betas
Lydia Khashina
3,015 PointsI've already solved my problem, thanks.
Я тоже из России. Приятно видеть здесь своих :)
Saam Zonoozi
1,962 PointsLydia, how did you solve your problem? I'm also getting [UIImageView] does not have a member named indexOf. I'm using XCode 6.4.
Sasha Kiselev
2,382 PointsThis is a solution for the XCode 7 betas in XCdoe 6 you should just follow the video
Kris Larsen
8,015 PointsI have XCode 7 but Sasha Kislev's code does not work for me.
can someone tell me why?
Rick Matsumoto
2,547 PointsKris, I'm running Xcode 7.1.1 and got the following code to work. Make sure you have the bangs(!). Also, if you just pasted Sasha's code snippet above, note that playlistArray should be playlistsArray.
let playlistImageView = sender!.view as! UIImageView
if let index = playlistsArray.indexOf(playlistImageView) {
let playlistDetailController = segue.destinationViewController as! PlaylistDetailViewController
playlistDetailController.playlist = Playlist(index: index)
}
Jacob Dobson
5,122 PointsI can confirm that Rick's answer works on the very recent version of Xcode (7.2)!
Van Doan
32,285 PointsThe above issue could be a syntax one as well.
David's and Sasha's has it: if let index = playlistArray.indexOf(playlistImageView) {
Where as Rick has it: if let index = playlistsArray.indexOf(playlistImageView) {
Notice the missing "s". So if you get an error about an unresolved identifier, it's probably that.
Sasha Kiselev
2,382 PointsSasha Kiselev
2,382 PointsI am also using Xcode 7 beta 3 same problem, please help anyone