Re: Any way to synthesize KVC compliant collections?
Re: Any way to synthesize KVC compliant collections?
- Subject: Re: Any way to synthesize KVC compliant collections?
- From: Quincey Morris <email@hidden>
- Date: Wed, 6 Oct 2010 03:51:32 -0700
On Oct 6, 2010, at 03:18, Citizen wrote:
> Is there any way to synthesize (using @synthesize) KVC compliant collections?
>
> I know there are scripts in the Xcode scripts menu to generate declarations and definitions along the lines of:
>
> - (NSArray *) myArray;
> - (unsigned) countOfMyArray;
> - (id) objectInMyArrayAtIndex:(unsigned)theIndex;
> - (void) getMyArray:(id *)objsPtr range:(NSRange)range;
> - (void) insertObject:(id)obj inMyArrayAtIndex:(unsigned)theIndex;
> - (void) removeObjectFromMyArrayAtIndex:(unsigned)theIndex;
> - (void) replaceObjectInMyArrayAtIndex:(unsigned)theIndex withObject:(id)obj;
>
> But is there a way to use properties to generate these methods?
No, @synthesize cannot generate these methods.
However, it's not entirely clear what you are expecting/hoping will happen. Unlike accessors (getters/setters) for scalar properties, these accessors are optional (roughly -- these methods must be implemented in certain combinations to be recognized), so synthesized methods don't seem useful. If you need the methods at all, then you need custom code in them that can't be synthesized.
Are you running into a specific difficulty?
BTW, you left one method out of your list:
(void) setMyArray: (NSArray*) theArray;
It's also worth keeping in mind that due to a historical irregularity (design flaw), if you implement the myArray getter you can't use the NSArray proxy object that's normally returned by valueForKey:@"myArray" -- when you've implemented countOfMyArray/objectInMyArrayAtIndex: -- so in those circumstances you have to return a real array or write your own proxy.
One final quibble: The type of all the index parameters is NSUInteger, not unsigned.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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