Re: [CORE DATA] Custom accessors question
Re: [CORE DATA] Custom accessors question
- Subject: Re: [CORE DATA] Custom accessors question
- From: email@hidden
- Date: Tue, 14 Feb 2006 00:21:54 -0800
Aurélien Hugelé wrote:
Hi list
i prefer implementing core data accessors to get Xcode completion,
and many compilation checking instead of using valueForKey/
mutableSetValueForKey.
Thanks to Xcode, I can get the implementation code quickly by right
clicking on any of my properties and asking for "Copy Method
Implementations to Clipboard". That's nice.
But something puzzle me, why is the the "get" accessors not
implemented?
asking for implementations of my "persons" to-many relation ship
gives me:
- (void)addPersonsObject:(GCMKCorePerson *)value
{
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value
count:1];
[self willChangeValueForKey:@"persons"
withSetMutation:NSKeyValueUnionSetMutation
usingObjects:changedObjects];
[[self primitiveValueForKey: @"persons"] addObject: value];
[self didChangeValueForKey:@"persons"
withSetMutation:NSKeyValueUnionSetMutation
usingObjects:changedObjects];
[changedObjects release];
}
- (void)removePersonsObject:(GCMKCorePerson *)value
{
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value
count:1];
[self willChangeValueForKey:@"persons"
withSetMutation:NSKeyValueMinusSetMutation
usingObjects:changedObjects];
[[self primitiveValueForKey: @"persons"] removeObject: value];
[self didChangeValueForKey:@"persons"
withSetMutation:NSKeyValueMinusSetMutation
usingObjects:changedObjects];
[changedObjects release];
}
why don't the implementations contains:
It probably should, its should also include setPersons as well.
-(NSMutableSet*)persons
{
NSMutableSet* value;
[self willAccessValueForKey:@"persons"]
value = [self primitiveValueForKey:@"persons"];
[self didAccessValueForKey:@"persons"];
return value;
}
???
*MUST* I *ONLY* use [myObject mutableSetValueForKey:@"persons"] to
get the persons ? or is my implementation above correct ?
what happens if I use [myObject mutableSetValueForKey:@"persons"]
accessor, but have implemented -(NSMutableSet*)persons above ? will
my custom accessor be called?
Yes, it will. And if you are dealing with NSArray/TreeController
implement setPersons if you want to override the setting process,
otherwise, your add/remove calls to NSArrayContoller will not do
anything you expect (custom logic) outside of your own code. Thats
because in one way or another, those controllers use [NSMutableSet
setSet:] style access......
This is not explicitly mentioned in the Docs AFAIK.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden