• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [CORE DATA] Custom accessors question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >[CORE DATA] Custom accessors question (From: Aurélien Hugelé <email@hidden>)

  • Prev by Date: Re: Class Memory Management
  • Next by Date: Re: Core Data, transient ivars and undo
  • Previous by thread: [CORE DATA] Custom accessors question
  • Next by thread: [CORE DATA] Custom accessors question
  • Index(es):
    • Date
    • Thread