Group Group Group Group Group Group Group Group Group

MyLocations pg 103 - location! is an unresolved identifier

#1

I’m getting a “Use of unresolved identifier ‘location’” error when trying to prepareForSegue where we are implementing the Tag Location view, where controller.coordinate = location!.coordinate. I believe i have everything hooked up correctly and have even copy-pasted on top of my own code with no difference. Everything in the storyboard seems to be good as well. The placemark property (controller.placemark = placemark) does not have an error, and i believe that is also coming from the CurrentLocationViewController as well. How does the LocationDetailViewController get the location property? Through the typecast that happens immediately before it, correct? Any pointers on what might be going wrong?

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "TagLocation" {
        let navigationController = segue.destinationViewController as! UINavigationController 
        let controller = navigationController.topViewController as! LocationDetailViewController
        
        controller.coordinate = location!.coordinate
        controller.placemark = placemark 
    }
}
#2

Ah! Whoops. I was calling this prepareForSegue(sender) in LocationDetailsViewController.swift, rather than in CurrentLocationViewController.swift. Now it makes sense why it couldn’t see the location property! I had assumed it was going to use some segue magic to see that property.