user3581248
user3581248

Reputation: 1014

Xcode 8 automatic NSManagedObject sublass codegen vs transient properties

Since Xcode 8 provides a seemingly great possibility to skip the generation of the NSManagedObject subclasses code and does it itself I wanted to use it in my app. However, I also wanted to use some transient properties for the sake of grouping the objects while using the NSFetchedResultsController. Is this possible to somehow achieve or do I have to traditionally generate the classes and write these properties' implementation by myself?

Upvotes: 1

Views: 253

Answers (2)

Satachito
Satachito

Reputation: 5888

There's no need to subclass it, try mark your property as transient enter image description here

Then you will be automatically able to access this property.

func insertNewObject(_ sender: Any) {
    let context = self.fetchedResultsController.managedObjectContext
    let newEvent = Event(context: context)

    // If appropriate, configure the new managed object.
    newEvent.timestamp = NSDate()
    newEvent.someT = "ABC"

Upvotes: 0

Ryan H.
Ryan H.

Reputation: 2593

I do not think this is possible without generating the NSManagedObject subclasses.

This is likely what the "Category/Extension" codegen option helps to address. This codegen option is useful for creating properties (attributes) that you do want Core Data to manage.

Upvotes: 1

Related Questions