Re: subclass of NSManagedObject not behaving as expected
Re: subclass of NSManagedObject not behaving as expected
- Subject: Re: subclass of NSManagedObject not behaving as expected
- From: Chris Hanson <email@hidden>
- Date: Sat, 21 Apr 2007 22:15:57 -0700
On Apr 20, 2007, at 7:39 PM, Gonzalo Castro wrote:
My EmployeeMO.m subclass contains the methods found here:
http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueObserving/Concepts/DependentKeys.html
That's probably the problem. You need to write accessor methods for
properties that are managed by Core Data -- that is, specified in your
model -- differently than those for regular NSObject subclasses.
http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html
In this case, the accessors for your "firstName" property would look
like this:
- (NSString *)firstName {
[self willAccessValueForKey:@"firstName"];
NSString *value = [self primitiveValueForKey:@"firstName"];
[self didAccessValueForKey:@"firstName"];
return value;
}
- (void)setFirstName:(NSString *)value {
[self willChangeValueForKey:@"firstName"];
NSString *temp = [value copy];
[self setPrimitiveValue:temp forKey:@"firstName"];
[temp release];
[self didChangeValueForKey:@"firstName"];
}
If you change your accessors for your "firstName" and "lastName"
properties to look like this, you should be fine. Your "fullName"
property -- since it's not declared in your model -- doesn't need
these kinds of changes, it can just use [self firstName] and [self
lastName] as it undoubtedly does already.
-- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden