supotuco (32) [Avatar] Offline
Line 62 of BooksCollectionViewController.swift is = self.fetchedResultsController.object(at: selectedIndexPath)

suggested fix is

(edit) = self.fetchedResultsController.sections?[selectedIndexPath.section - 1].objects?[selectedIndexPath.row] as? Book
Craig Grummitt (48) [Avatar] Offline
Hi supotuco, thanks again for your feedback. I assume you're talking about page 332, right? I'm squinting my eyes at your suggestion and I can't work it out! smilie Am I missing something? Aren't both lines the same?
supotuco (32) [Avatar] Offline
I did mistype the suggestion.

it was supposed to be = self.fetchedResultsController.sections?[selectedIndexPath.section - 1].objects?[selectedIndexPath.row] as? Book

updated original comment
Craig Grummitt (48) [Avatar] Offline
Hi supotuco - thanks for updating your question. Could I ask your reasoning behind the suggestion? Is the line in the book not working?
supotuco (32) [Avatar] Offline
I get a crash when I select a book in the BookCollectionViewController
Craig Grummitt (48) [Avatar] Offline
Ah ok. What sort of error messages are you seeing in the console?
Is it crashing on that line?
supotuco (32) [Avatar] Offline
I don't know how to use the xcode stack trace to find the line so I attached my console output.

Steps to reproduce.

1) Checkout Chapter11.7.StoreCoreData branch from book repo
2) Add a book
3) Switch to collection view
4) Click on a book
Craig Grummitt (48) [Avatar] Offline
I've finally had a chance to have a proper look at this, thank you for your steps to reproduce, that cleared things up. You're right - there's a bug there when clicking on a book in the collection view in the core data section.

Your suggestion is definitely one way to solve it, digging the section out manually of the fetched results.

I solved this a different way, in the cellForItemAt method, generating an updated index path from the selectedIndexPath but forcing it to section 0, so I could still take advantage of the object:at method:

let updatedIndexPath = IndexPath(row: selectedIndexPath.row, section: 0) = self.fetchedResultsController.object(at: updatedIndexPath)

I'm updated the repo, thanks again for discovering this and letting me know!