Hi all,
in an existing project I have tried to introduce Core Data long after the project was created, so its model is already in place. I have created the xcdatamodel and added my only class to it. That class should act as a global storage for objects in my application. The class properly implement NSManagedObject and I have verified it gets created and saved in context, also retrieved with a fetch result.
The way of saving data in this class is by means of NSMutableArray. But this is just not working. Here's a fragment of this class:
@interface WZMPersistentStore : NSManagedObject<NSCoding> {
NSMutableArray *persistentStorage;
}
@property(nonatomic,retain) NSMutableArray *persistentStorage;
-(void)add:(id)element;
-(void)remove:(id)element;
-(id)objectAtIndex:(NSUInteger)index;
-(NSUInteger)num;
@end
In the implementation I also override the initWithEntity like this:
- (id)initWithEntity:(NSEntityDescription*)entity insertIntoManagedObjectContext:(NSManagedObjectContext*)context {
NSLog(@"init with entity");
[super initWithEntity:entity insertIntoManagedObjectContext:context];
return [self init];
}
The init method only initialize the mutable array, and I can see from the log that it gets properly called by the app delegate when creating entity. The add method just send message insertObject to persistentStorage. The questions that come from this:
- Am I doing "conceptually" right ? I mean, is it correct to have instance variable in managed object and initialize like I did ?
- when ns logging the size of the persistentStorage I always get 0 even when logging a moment after the addObject message (edit: taht's not true, I have verified again and I correctly got 1 added).
- The object stored in managed object class trough persistentStorage are normal class with attribute. Is there something I need to do with them ? I suppose not because I am not getting any error at runtime.
thanks