Errors at beginning pages of Chapter 21

I just finished Chapter 21 till page 358. Does anyone know a simple solution to these errors I’m getting? I moved the Photo.swift file to the bin. But still get a couple of errors. Heres my work:

I think you have hidden duplicates of the Core Data files shown in your Project Navigator. Generating the Core Data files is more problematic in Xcode 8.1 than in Xcode 7.3. Someone else was having the same problem last week. See that thread for solutions:

Still doesn’t work. Probably better off buying the 6th ed.

Oh boy. It seems like anyone making the transition to Xcode 8 and Core Data has had the duplicate file problem. If the files are hidden, I’m not sure how you can delete them, but the suggestions in the linked thread seem to suggest that if you change a project setting, then regenerate the files, that seems to work.

If you are using git, then you can revert back to the state of your project before adding those files. I’m surprised the book didn’t cover some basic git. It really is a requirement when you write a program that is more than 20 lines of code.

Probably better off buying the 6th ed.

Hah. You only have one more chapter to go!

I’ve been trying the suggested solutions as well as a ton of suggested ones online but still can’t solve it…

I was told by a more experienced coder than me that Xcode 8 “handles the NSManagedObjectSubclass generation itself” now but it didn’t really solve anything…

Alright let me be more specific. When I have the NSManagedObjectSubclass-es I get the duplicate file error:

Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

When I delete the 2 subclasses I get a TON of errors, mostly saying that Photo has no attribute “image” or “NSManagedObjectSubclass”.

Additionally, the enum PhotosResult

case Success([Photo])

has been giving me a lot of errors consistently. It may be related?

Based on the link you sent me in the original thread, it seems that an extension needs to be used - Xcode automatically manages all the model data but “image” needs to be an extension.

The highest answer in the thread you linked before says this much:

Option 3: "Category/Extension"

Use this option if you have custom properties that do not need to be managed by Core Data.
Use the model editor to create the entities and associated attributes that you want Core Data to manage.
Ensure the Module option is set to Current Product Module and the Codegen option is set to “Category/Extension”.
Create your own NSManagedObject subclass with the properties that you will self manage.
Do not use the NSMangagedObject subclass generator. The required files are automatically generated for you by Xcode (however they do not show up in your project navigator).

// Subclass NSManagedObject in Entity.swift
class Entity: NSManagedObject { // Self managed properties }

// Optional extension in Entity.swift
extension Entity { // Override NSManagedObject methods }

Would you help me implement this in the Photorama code? I am unsure where/how I could code an extension that only manages the photo subclass.

tl;dr, I know that Xcode 8 manages the stuff in core data automatically, and invisibly, now. But the image property is NOT in core data and needs to be added as an extension somehow…