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 Using a Navigation Controller With Segues Modifying the UI

gökhan sayılgan
gökhan sayılgan
2,285 Points

its not working at x code 7.2

i have check all questions and approaches before me non is solving my problem. i have write everything same in the video nothing has changed. first error is use a " ! " operator for "as" key (i have done that but still doesn't work) . second error is intance member segueLabelText cannot be used on type 'PlaylistDetailViewController'.

please reload this video for new version of x code or for now send us a solve of that problem just and save the day

thank you

gökhan sayılgan
gökhan sayılgan
2,285 Points
import UIKit

class  PlaylistMasterViewController: UIViewController {    

    @IBOutlet weak var aButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "showPlaylistDetail" {
            let playlistDetailController = segue.destinationViewController as
                PlaylistDetailViewController
            PlaylistDetailViewController.segueLabelText = "Yay, you pressed the button"            
        }
    }
}
gökhan sayılgan
gökhan sayılgan
2,285 Points
import UIKit

class PlaylistDetailViewController: UIViewController {
    @IBOutlet weak var buttonPressLabel: UILabel!

    var segueLabelText: String = ""

    override func viewDidLoad() {
        super.viewDidLoad()
        buttonPressLabel.text = segueLabelText
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

9 Answers

Albert González
Albert González
22,953 Points

In this video, the code is for the old Xcode and not for the new Xcode 7. You have to download the project from the downloads and see the code asociated.

gökhan sayılgan
gökhan sayılgan
2,285 Points

i compare that file with mine there is no difference (cuz i also tried bang operator) mine didn't work but that one have is working. Any way it should be my mistake or something must be missing thank you for solving my problem

Albert González
Albert González
22,953 Points

Zachary, make a clean of your project

This line is incorrect: PlaylistDetailViewController.segueLabelText = "Yay, you pressed the button"

Corrected: playlistDetailController.segueLabelText = "Yay, you pressed the button"

You're supposed to call the constant.

Even with the project file downloads, I'm unable to get the app to build. The "as!" doesn't work. App only crashed on build.

gökhan sayılgan
gökhan sayılgan
2,285 Points

1)download project zip file 2) open it with x code 3)close pdf explanation about difference between as and as! operators 4) open again your project 5)copy and paste masterViewController codes to your own project from download 6)copy and paste detailViewController codes to your own project from download

Note= probably you forget to replace master or detail view controller codes with downloaded file codes

My code:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "showPlaylistDetail" {
            let playlistDetailController = segue.destinationViewController as! PlaylistDetailViewController
            playlistDetailViewController.segueLabelText = "Yay! You pressed the button!"
        }
}

I'm running into the same issue as people above. I get an error saying "Use of unresolved identifier 'playlistDetailViewController'.

Any ideas?

Restarted Xcode a few times and this resolved on it's own. Odd, but happy to be able to move on.

Kyle Robertson
Kyle Robertson
31,600 Points

Instead of typing out playlistDetailController.segueLabelText, I copied and pasted it from the constant declared above, and then the app built fine for me.

gökhan sayılgan
gökhan sayılgan
2,285 Points

thank you guys i have done it as Albert said

David Urbonas
David Urbonas
9,405 Points

This is infuriating!

I've tried all of the above and still doesn't work!

keeps asking for a "!" after as. What's going on?

Albert González
Albert González
22,953 Points

Did you change the "!" for the "?"

David Urbonas
David Urbonas
9,405 Points

Not sure what you mean Albert

David Urbonas
David Urbonas
9,405 Points

I've copy and pasted the code from the download files and still getting this error "UIViewController" is not convertible to "PlaylistDetailViewController"; did you mean to use "as!" to force downcast.

Adding the "!" to "as" I then get a console error of "Unknown class PlaylistDetailViewController in Interface Builder file."

thoughts?