1

First of all, here's my code:

let flickerFetcher : FlickrFetcher = FlickrFetcher()

var photos : UIImage[]? = UIImage[]() {
    didSet { self.appsTableView.reloadData() }
}

func prepareImageViewController(ivc: ImageViewController, toDisplayPhoto photo: NSDictionary)
{
    ivc.imageURL = flickerFetcher.URLforPhoto(photo, format: FlickrFetcher.FlickrPhotoFormat.Large)
    ivc.title = photo.valueForKeyPath(flickerFetcher.FLICKR_PHOTO_TITLE) as String
}

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
 //   NSLog("Prepare for Segue beginning")
    if sender!.isKindOfClass(UITableViewCell) {
      //  NSLog("Sender is UITableViewCell")
        var indexPath : NSIndexPath = self.tableView.indexPathForCell(sender as UITableViewCell)
        if indexPath != nil {
          //  NSLog("IndexPath is nil")
            if segue!.identifier == "Display Photo"{
               // NSLog("Segue Identified")
                if segue!.destinationViewController.isKindOfClass(ImageViewController) {
                    NSLog("DestinationViewController is ImageViewController")
                    var destinationController = segue.destinationViewController as ImageViewController
                    if let photoDict = self.photos?[indexPath.row] as? NSDictionary {
                        self.prepareImageViewController(destinationController, toDisplayPhoto:photoDict)
                    }

                }
            }
        }
    }

}

I've narrowed the problem down to the implementation of the prepareImageViewController on the last line that gives me a crash linked to swift_dynamicCast. That I can't seem to figure out.

Sawyer05
  • 1,604
  • 2
  • 22
  • 37

1 Answers1

2

Try and make sure your photos dictionary is before using it.

if let photoDict = self.photos?[indexPath.row] as? NSDictionary {
    self.prepareImageViewController(destinationController, toDisplayPhoto:photoDict)
}
Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
  • Thanks Connor, I had that in originally, but took it out when I was trying to figure out what was wrong. Still getting the error with it in – Sawyer05 Jun 26 '14 at 10:52
  • Yep, very same. Does this look right? `func URLforPhoto(photo: NSDictionary, format: FlickrPhotoFormat) -> NSURL { return NSURL(coder: self.urlStringForPhoto(photo, format: format) as NSCoder) }` – Sawyer05 Jun 26 '14 at 11:42
  • I tried that, and I'm no longer getting the error, but it seems the photo still isn't opening. When the segue takes place, it should open the photo and the name of the photo should be the title of the new view controller. The title is now showing but the photo isn't – Sawyer05 Jun 26 '14 at 11:56