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
Austin Hawks
Courses Plus Student 3,003 PointsAmbiguous use of view Error I followed the instructions on the video, but I keep on getting the error ambiguous use of
I'm trying to downcast the sender: AnyObject to UIImage And how do you post code so that it shows on the black screen where the codes supposed to go?
{
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if segue.identifier == "showPlaylistDetailSegue" {
let playlistImageView = sender.view as UIImageView
if let dex = find(playlistImageArray, playlistImageView) {
let playlistDetailController = segue.destinationViewController as! PlaylistDetailViewController
playlistDetailController.playlist = Playlist(index: dex)
}
}
}
3 Answers
Jari Koopman
Python Web Development Techdegree Graduate 29,349 PointsI think it's because of the Swift 2.0 update. I tried it in my own project and if you add a question mark after "sender" like this:
let playlistImageView = sender?.view as! UIImageView
if let index = playlistArray.indexOf(playlistImageView) {
let playlistDetailController = segue.destinationViewController as! PlaylistDetailViewController
playlistDetailController.playlist = Playlist(index: index)
}
and that works perfectly fine!
Hope this helped!
Kind regards, Jari
Austin Hawks
Courses Plus Student 3,003 PointsYep, that did work. Thanks! But I'm still getting the ambiguous use of view error in a different spot now. I commented in the code below where the errors showing up.
override func viewDidLoad() { super.viewDidLoad() for dex in 0..<playlistImageArray.count { playlistImageArray += [playlistImageView, playlistImageView2, playlistImageView3, playlistImageView4, playlistImageView5, playlistImageView6] let playlist = Playlist(index: dex) let playlistImage = playlistImageArray[dex] playlistImage.image = playlist.icon playlistImage.backgroundColor = playlist.backgroundColor } //the ambiguous view is error's on this line.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { //the yellow mark is on this line
if segue.identifier == "showPlaylistDetailSegue" {
let playlistImageViews = sender?.view as! UIImageView
if let dex = playlistImageArray.indexOf(playlistImageViews) {
/*find returns the number the object in the array is*/
let playlistDetailController = segue.destinationViewController as! PlaylistDetailViewController
playlistDetailController.playlist = Playlist(index: dex)
}
}
}
Jari Koopman
Python Web Development Techdegree Graduate 29,349 PointsI've pasted your code in my existing project and commented my own code but I don't get any errors. Could you send me a download of your complete project so I can have a look at it?
Download my project: Here This project works perfectly fine!
Hope this helped!
Kind regards, Jari
Issavara Polanun
5,480 PointsThis is also no longer working on Swift 3.0. Anyone know how to make it work for Swift 3.0?