In an existing project, I tried to introduce Core Data long after the project was created, so its model is already installed. I created xcdatamodel and added my only class to it. This class should act as a global repository for objects in my application. The class implements NSManagedObject correctly, and I checked that it is created and stored in context, is also retrieved with the selection result.
The way to save data in this class is done using NSMutableArray. But that just doesn't work. Here's a snippet 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 initWithEntity as follows:
- (id)initWithEntity:(NSEntityDescription*)entity insertIntoManagedObjectContext:(NSManagedObjectContext*)context {
NSLog(@"init with entity");
[super initWithEntity:entity insertIntoManagedObjectContext:context];
return [self init];
}
init , , .
add message insertObject persistentStorage.
, :
- "" ?
,
, ?
- ns
persistentStorage 0
addObject (:
, ,
1 ).
- ,
persistenceStorage
.
-,
? , ,
.