I have an iOS app containing a Core Data model with 6 entities. The entity Name
is set up as follows:
Class Name: Name
Regarding Problem 1, setting the Codegen popup in the Inspector for an entity in an .xcdatamodel is supposed to work like this:
Category/Extension tells Xcode to generate one file, ClassName+CoreDataGeneratedProperties.
Class Definition tells Xcode to generate two files, the above-named file, plus ClassName+CoreDataClass.
However, there appears to be a bug, in Xcode 8.2. If, after changing one of these popups, you simply Build (⌘B) or Run (⌘R), your changes will not take effect. For example, if you changed from Class Definition to Category/Extension and even manually deleted the second file, it will reappear. You may even find that the popup reverts back to the original setting.
In order for changes in these popups to become effective, you must
During the next build (which may occur automaticallly when the project opens if you have an @IBInspectable in a storyboard), the affected files in Derived Data will be generated or deleted to conform to your new setting.
UPDATE 2016-12-22: Thank you for the comment, Ashley. I've now written up and submitted this to Apple Bug Reporter: 29789727. Update 2017-02-08: Apple has closed 29789727 as it supposedly duplicates 21205277.
Looks like Xcode 8.2.1 won't turn off codegen.
But you can manually delete codeGenerationType="category"
from .xcdatamodel contents file.
Close Xcode, delete codeGenerationType
, delete DerivedData folder and rebuild.
Will wait for fix in future releases.
I got completely stuck with Problem 4 and none of the above worked for me. I use code generation. To resolve it I did the following steps:
codeGenerationType="class"
PS: If you choose to Manually create your NSManageObject subclasses rather then using Code Generation, then make sure you remove codeGenerationType="class"
from your entities in the XML file in step 2.
Problem 4 can be fixed (at least in the latest beta, v. 6) by selecting all the entities you want auto-generated, and then in the inspector clearing the Class -> Module field so that it defaults to "Global namespace".
Regarding problem 2: Core Data's "optional" flag has nothing to do with the Swift concept of an optional. They are unrelated and do not mean the same thing. Marking a Core Data attribute as non-optional does not imply that it's non-optional as Swift defines the term. The difference is:
Problem #4 sounds like Xcode getting its state confused, and may be fixed by voodoo like manually clearing the derived data folder (again, I know). I can't currently reproduce it, but that doesn't mean it's not a bug in the current beta.
It's actually pretty easy to fix it.
Go to configuration:
Then delete the points. These are only there in older projects. The import statements are fixed after this and you are good to go.
You also should put your models to the Global namespace. Mine were in a extra namespace, but i have no idea why.
Apples approch is that you can use this in a custom framework.
This feature is pretty nice, if you get it working ;)