Question

I have created a simple base class with 3 parameters (OBJECT1, see below) and implemented a Core Data model where there is one entity derived from this class, with one attribute (order).

Problem is, when I save the context, only the dynamic parameters (created in the model) are stored in the sql file, those that are not included in the model (created manually) do not persist... So the name1, name2 and name3 params have values during the first time I create the object BUT at the next App run, since I don't create them anymore... they are null...

Same story if I create a derived classes from OBJECT1 class...

Is there a way to store the whole object permanently and use Core Data model only for those key attributes that require indexing?

BASE OBJECT1:

@interface OBJECT1 : NSManagedObject
{
    NSString *name1;
    NSString *name2;
    NSString *name3;
}

    @properties (nonatomic,assign) NSNumber *order;
    @properties (nonatomic,copy) NSString *name1;
    @properties (nonatomic,copy) NSString *name2;
    @properties (nonatomic,copy) NSString *name3;

@end

@implementation OBJECT1

    @dynamic order;

    @synthesize name1;
    @synthesize name2;
    @synthesize nam3;

@end
Was it helpful?

Solution

Managed object classes are normal classes, you can add instance variables to them and use them. That doesn't mean that this data will magically get saved because it is unrelated to the Core Data store.

If you're using Core Data, add all of the information that you want to be persisted into the model so that Core Data can control / save it for you. Running 2 different schemes to save data from the same object will be confusing and error prone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top