Xcode NSManagedObject subclass contains optionals when they are marked as non-optional

"Optional" means something different to Core Data than it does to Swift.

  • If a Core Data attribute is not optional, it must have a non-nil value when you save changes. At other times Core Data doesn't care if the attribute is nil.
  • If a Swift property is not optional, it must have a non-nil value at all times after initialization is complete.

Making a Core Data attribute non-optional does not imply that it's non-optional in the Swift sense of the term. That's why generated code makes these properties optional-- as far as Core Data is concerned, it's legal to have nil values except when saving changes.


This is a known issue. Some people change it to non-optional with no adverse effects, I keep it the way it was generated and hope for early fix.

It always helps if you submit a bug to Apple to increase visibility and priority.


Create managedobject class and change the entity class type to manual and add these classes to your project scope.

Edit your managedObject to make them non-optional. This means you need to maintain this class yourself and do any changes both in the core data model and the class

If your data model is stable and won't be changed then you can use this.