Core Data and @dynamic
I'm new with Core Data and there are some issues that I don't understand yet.
I have a entity called GCS (a subclass of NSManagedObject for Core Data)开发者_JAVA百科:
@implementation GCS
@dynamic eye;
@dynamic ...
@dynamic ...
It works fine with Core Data when I do this:
GCS *failedBankDetails = [NSEntityDescription
insertNewObjectForEntityForName:@"GCS"
inManagedObjectContext:context];
failedBankDetails.eye = [NSNumber numberWithInt:12];
But then, in another class I have a property of GCS type:
@interface ModelManager : NSObject
{
GCS *tempGCS;
}
@property (nonatomic, retain) GCS *tempGCS;
...
In a method of ModelManager I tried this:
tempGCS.eye = [NSNumber numberWithInt:0];
But raised exceptions: Failed to call designated initializer on NSManagedObject class 'GCS' -[GCS setEye:]: unrecognized selector sent to instance 0x4d32ac0
Why cant I use the dot notation now? I think the @dynamic is the clue, but I shouldn't change it because I need to use it for Core Data, right?
Please help me and sorry for my english. Thanks!
Dot notation has nothing to do with it, you'd get the same error if you called [tempGCS setEye:...]
. The error is that you neglected to call initWithEntity:insertIntoManagedObjectContext:
when creating the object in tempGCS
; in particular, [[GCS alloc] init]
will not work correctly.
精彩评论