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
Alexandre Perron
4,410 PointsSwift Course Question - Segues
Hello all, this is my following code in "PlaylistMasterViewController.swift" while following the "Build a Playlist Browser App for iPhone" course.
import UIKit
class PlaylistMasterViewController: UIViewController {
@IBOutlet weak var aButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
aButton.setTitle("Press Me!", forState: .Normal)
}
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
playlistDetailController.segueLabelText = "Yay! You Pressed The Button"
}
}}
on the "let playlistDetailController" line, it gives me the error "anyObject is not convertible to 'PlaylistDetailViewController'; did you mean to use as! to force downcast?"
I do not understand what this line means and how I can resolve this issue? Can a kind soul enlighten me?
Cheers, Alex
2 Answers
Jhoan Arango
14,575 PointsHello Alexandre:
The down casting is a whole different topic which you won’t find here in detail yet. But If you are curious about it I recommend reading one of the answers given to me a few months ago. Here is the link to it.
Now, on your question... resolving the issue, Xcode gives you a suggestion that says “fix it”. It will help you solve your problem. In this case I think its best to use as! to downcast. That should solve your problem, but you may not understand it yet until you read more about down casting.
Hope this helps
Sherry Fleming
Courses Plus Student 6,680 Pointsno it didn't - it allowed the code to at least compile, but the Detail view has no content- they need to update this course- the "Cocoa" template he had us start with wasn't even relevent