Xcode 8.1 beta 3 error

I am working on an app that will be using CoreData and have been using the new Core Data by Tutorials book because I haven’t been let down by a single RW book yet. The being said, I am running Xcode 8.1 beta 3 and getting a ton of errors when trying to generate a class from an entity using Xcode. The biggest one so far is:

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

The app will no longer compile if I generate the files as stated in the book. Has anyone else seen this or found a workaround?

OK. Found the answer. DO NOT GENERATE the two files as stated in the book if using this version of Xcode. The examples will work just fine. Xcode is already referencing the information in the CoreData model.

I got the same error and had dealt with it before I got the book. On StackOverFlow, there’s all kinds of answers including that this issue is fixed in Xcode 8.1, even though I’m still experiencing it in Xcode 8.1. YMMV, but the trick that worked for me is in Data Model Inspector for the Bowtie entity, set the Module to “Current Product Module” and Codegen to “Manual/None”. I’m looking forward to learning what these two settings does when I get further into the book.

And of course following the random advice in StackOverFlow will fix one thing but break another. In the next step of the book where you save and retrieve a test bow tie in app delegate, I got this error in the console:

Could not cast value of type ‘NSManagedObject_Bowtie_’ (0x600000055f60) to ‘Bow_Ties.Bowtie’ (0x104eb7988).

Again, YMMV, but I end up setting Module to blank and kept Codegen to “Manual/None” and it fixed this issue. Let’s see how long before I come across another one because of this setting, lol.

1 Like

Okay. P. 75 (Chapter 3: Core Data Stack) explains the Codegen field in the Data Model inspector.

Essentially since Xcode 8 defaults to have this on (I haven’t figured out if there’s a way to default it to off), as soon as we create entities, the EntityName+CoreDataClass.swift and EntityName+CoreDataProperties.swift are created in the derived data folder. So once we select Editor\Create NSManagedObject subclass, we are asking for the same files to be created in our project folder.

Setting the Codegen to “Manual/None” (make sure to hit Enter after as it doesn’t stick sometimes), delete the derived data folder (File\Project Settings, click on the arrow next to the derivedData folder path to open it in Finder, delete it), clean and rebuild seems to fix this issue consistently.

Interesting thing is that i have done all the exercises of this book for iOS 9 and didn’t notice anything about this error before. Anyway, I put my settings here as a screenshot, this worked for me and I wonder what really changes and how both works…?

I think in Xcode 8, Codegen is set to “Class Definition” instead of “Manual/None” like you have. At least that’s the case for my version of Xcode 8.

1 Like

My response to this post may be helpful: Chapter 2: Error 'Bowtie' is ambiguous for type lookup in this context - #2 by harri

The idea for this sample app is simple. There will be a table view with a list of names for your very own “hit list”. You’ll be able to add names to this list and eventually, you’ll use Core Data to make sure the data is stored between sessions. We don’t condone violence on this site so you can think of this app as a “favorites list” to keep track of your friends too, of course! :wink:

Hey all! Thanks for letting us know about this problem and for helping others out.

We’ve updated Chapters 2 and 3 of the book to help avoid this issue under Xcode 8.1:

https://www.raywenderlich.com/148554/core-data-tutorials-updated

All Core Data by Tutorials PDF customers get this as a free update!

1 Like

after entering code on page 47/48 of the updated edition the app crashes with the following errors:

CoreData: warning: Unable to load class named ‘Bow_Ties.Bowtie’ for entity ‘Bowtie’. Class not found, using default NSManagedObject instead.
Could not cast value of type ‘NSManagedObject_Bowtie_’ (0x17404e640) to ‘Bow_Ties.Bowtie’ (0x100049988).
2016-12-02 21:38:06.701037 Bow Ties[1828:410632] Could not cast value of type ‘NSManagedObject_Bowtie_’ (0x17404e640) to ‘Bow_Ties.Bowtie’ (0x100049988).

If you compiled before setting the Codegen to “Manual/None”, you need to change it and also set the Module to “Current Product Module”, you need to clean the DerivedData folder, clean the project. Remove any previously manually generated files for the model, create the NSManagedObjectSubclass again then build and run.