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 Passing Playlist Objects Using Segues

Christiaan Hendriksen
Christiaan Hendriksen
5,982 Points

Ambiguous reference to member 'view'

My app is crashing on the line:

let playlistImageView = sender!.view as UIImageView

with an error of:

Ambiguous reference to member 'view'

I've tried googling, but I have no idea what this means!

Christiaan Hendriksen
Christiaan Hendriksen
5,982 Points

I've made it build by changing the line to:

let playlistImageView = sender!.view! as! UIImageView

But this seems like a hack rather than a solution...

1 Answer

Sam Davis
Sam Davis
6,988 Points

I have gotten it working with the following code:

if let playlistImageView = sender!.view! as? UIImageView {
    if let index = playlistsArray.indexOf(playlistImageView) {
        if let playlistDetailViewController = segue.destinationViewController as? PlaylistDetailViewController {
            playlistDetailViewController.playlist = Playlist(index: index)
        }
    }
}

My guess is that Swift has changed a little bit since this video was made.