2016-05-09

I entered the code for the "Downloading and displaying the image data" section on pp. 327 - 330, but I now get an error. Comparing to the book and the solution file, it looks like I have everything typed in correctly. Some debug lines suggest Success but with a nil image. I'll try a detailed flow on paper and add more debug lines, but any thoughts or guidance on how to resolve? Thanks.

In Debug window:

viewDidLoad()
fetchRecentPhotos(completion:)
recentPhotosURL()
flickrURL(method:parameters:)
URL=https://api.flickr.com/services/rest?method=flickr.photos.getRecent&format=json&nojsoncallback=1&api_key=a6d819499131071f158fd740860a5a88&extras=url_h,date_taken
processRecentPhotosRequest(data:error:)
photosFromJSONData
photoFromJSONObject
photoFromJSONObject
. . .
photoFromJSONObject
photoFromJSONObject
Successfully found 55 recent photos.
fetchImageForPhoto(_:completion:)
processImageRequest(data:error:)
fatal error: unexpectedly found nil while unwrapping an Optional value

Failing code line:

Code:

super.viewDidLoad()
store.fetchRecentPhotos() {
(photosResult) -> Void in
switch photosResult {
case let .Success(photos):
print("Successfully found \(photos.count) recent photos.")
if let firstPhoto = photos.first {
self.store.fetchImageForPhoto(firstPhoto) {
(imageResult) -> Void in
switch imageResult {
case let .Success(image):
NSOperationQueue.mainQueue().addOperationWithBlock {
self.imageView.image = image     <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< dies
}
case let .Failure(error):
print("Error downloading image: \(error)")
}
}
}
case let .Failure(error):
print("Error fetching recent photos: \(error)")
}
}

Update: OK, never mind. I was tearing my hair out trying to see why "image" was nil. Turns out I didn't hook the IBOutlet up correctly linking the imageView to PhotosViewController, making "self.imageView" not have a "view", so that was the nil, not the right hand side. I saw this by running the book's solution and seeing that it worked as expected. I then started comparing my typed in version to the solution and poking around and then saw the connections difference. Whew!

Statistics: Posted by gkd720 — Mon May 09, 2016 2:21 pm

Show more