In Chapter 22, in the section titled "NSManagedObject and Subclasses," we read the instructions:
'Open Photorama.xcdatamodeld. Select the Photo entity and open the Data Model inspector. Locate the Codegen option and select Manual/ None.'
This is fine, however a bug in Xcode 8.2.1 (and some earlier releases) may affect you when you complete the section and build/run the project. You may get the compile-time errors:
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
Which is caused by an error similar to this output:
:0: error: filename "Entity+CoreDataClass.swift" used twice: '/Users/greg2/Desktop/Current/Swift/TestCD/Photo+CoreDataClass.swift' and '/Users/greg2/Library/Developer/Xcode/DerivedData/TestCD-alzkdocqjhuaigahqlichpzxvfvo/Build/Intermediates/TestCD.build/Debug-iphonesimulator/TestCD.build/DerivedSources/CoreDataGenerated/Model/Photo+CoreDataClass.swift'
This is saying that there are two files called Photo+CoreDataClass.swift, both are being compiled and hence the Photo CoreData Entity is being defined twice.
One workaround that works for me is to:
- Delete the files Photo+CoreDataClass.swift and Photo+CoreDataProperties.swift
- Remove them from the Project and Move to Trash
- Do a Product -> Clean from the main menu
- Regenerate the Photo Entity class files with Editor -> Create NSManagedObjectSubclass (whilst in the CoreData model)
However, this bug is sneaky, and sometimes you just have to keep playing with it. What is happening is that sometimes Xcode is generating the files for you during the Build phase, even when you don't want it to. And when the files are already part of your project, then you have two identical files being compiled into the project.
Here is an Apple Forum thread on the problem:
Once you get past this compiler/builder bug, the code in the book runs just fine!