26

After updating to Xcode Version 6.0 (6A313), when I add a new attribute to my xcdatamodeld entry, "Create NSManagedObject subclass" is not adding the new property to the generated header file. This works fine after closing Xcode 6, and then running Version 5.1.1 (5B1008). I repeated this process a couple of times with the same results. Do I need to do something to allow a new Xcode version to properly manage my data models, or recreate them, or is this possibly just a bug with the new Xcode?

Here are the specific steps I took:
1. Open DataModel.xcdatamodeld in Xcode 6.0 (GM Seed).
2. Select correct entity
3. Click + to add new attribute
4. Enter name and selected Boolean type for new attribute
5. Editor->Create NSManagedObject subclass
6. Ensure proper data model is checked, click next
7. Ensure correct entity is checked, click next
8. Choose location to save (using root project folder), select Create
9. Choose "Replace" in dialogue box
10. Look for variable in generated header file. Variable not present.
11. Close Xcode6
12. Repeat steps 1-10 in Xcode 5.1.1, worked correctly
13. Repeated this process twice to verify same results

Thanks for any help!

dcep1
  • 261
  • 3
  • 3

5 Answers5

45

Ok, I figured out a workaround but it would appear this is a bug.

For all the entities you want to regenerate, remove the existing files from disk try Editor->Create NSManagedObject subclass and select those classes that you have removed from disk.

The files that don't currently exist are regenerated. This fixed the issue for me.

d0n13
  • 942
  • 7
  • 20
  • 2
    Hmmm. This is not working for me. I had a few entities in my model and made a lot of changes to the schema. I just deleted all the swift files that related to the ManagedObects and used the menu Editor->Create NSManagedObject subclasses etc... However many times I tried I just got one file with the same name as the project name and the properties of whichever entity I had selected last. I have no data stored at all and used file->delete->move to trash to get rid of the existing files. Had to delete model and start again to get around it. Also tried cleaning, restarting, etc... – Bertie Oct 07 '14 at 18:08
  • The only thing that seems to work for me is to delete the file and then use file->new file->coreData->NSManagedObject subclass and follow the prompts from there. Must be a bug, right?... I hadn't emptied the trash after I deleted the files, but that shouldn't make a difference should it. – Bertie Oct 07 '14 at 18:12
  • 1
    Same problem here, I always get a file with the same name as the project name when I try to create a NSManagedObject Subclass, restarting Xcode doesn't help – fruechtemuesli Jan 04 '15 at 23:53
  • Solution works for Xcode 6.1.1! Thank you very much. – Eric Chen Jan 07 '15 at 18:55
0

I had the same problem, Xcode didn't generate new properties after I choose "Replace" files.
Just fix it doing next steps:

  • after you change or add new entity in .xcdatamodel select changed entity Class files at "Groups & Files" list
  • select "Delete" - "Move to Trash" (if need copy specific code from your class file)
  • now back to .xcdatamodel and select entity you changed
  • create new NSManagedObject subclass(use standard way)
SpartaqUA
  • 41
  • 1
  • 5
0

This requires a workaround, but specifically the quickest way I found was:

  1. Setup your project such that the generated files from the model, are in a folder of their own.

  2. When you need to add/change attributes to your model, multi-select the set of auto-generated files, and hit backspace (and select move them to Trash)

  3. Re-generate your set of NSManagedObject files from the Model, back into the same folder

Ed Manners
  • 459
  • 4
  • 8
0

Before deleting your files and/or the data model itself as suggested, check whether you have added the module name in the Xcode's Data Model Inspector under Entity/Class. If you have, removing it will solve the problem of auto generating the entity classes. It will, however, reintroduce the problem you fixed by adding it in the first place (see Swift - CoreData: warning: Unable to load class named)... With this in mind, it appears a better solution to add the @objc(<ClassName>) above the generated class than to add the module name in the inspector.

Community
  • 1
  • 1
Milos
  • 2,728
  • 22
  • 24
0

Old question. But here is my solution: just CLEAN it and BUILD again.

Menu: project > clean build folder and build again.

btw, here is the time of Xcode 9.

losiu
  • 39
  • 2