Re: Key-value observing and NSMutableArray
Re: Key-value observing and NSMutableArray
- Subject: Re: Key-value observing and NSMutableArray
- From: Scott Anguish <email@hidden>
- Date: Sat, 8 Nov 2003 18:27:41 -0500
On Nov 8, 2003, at 4:59 PM, Dustin Voss wrote:
Let's say my model has an NSMutableArray called "foobazi", and I have
implemented the following indexed key-value coding method:
- (void) insertObject:(Foobaz *)f inFoobaziAtIndex:(unsigned int)i
{
[foobazi insertObject:f atIndex:i];
}
Let's further say that I wanted to support key-value observing
manually. Will NSMutableArray call the appropriate key-value observing
methods itself? I don't see how it could, since it wouldn't know what
key to use.
No, that's why we call it manual. :-)
The key-value observing docs suggest that I should rewrite the above
function to:
[self willChange:NSKeyValueChangeInsertion
valuesAtIndexes:[NSIndexSet indexSetWithIndex:i] forKey:@"foobazi"];
[foobazi insertObject:f atIndex:i];
[self didChange:NSKeyValueChangeInsertion
valuesAtIndexes:[NSIndexSet indexSetWithIndex:i] forKey:@"foobazi"];
But an earlier e-mail I saw on the subject (from this list) said I
should rewrite the above function to:
[self willChangeValueForKey:@"foobazi"];
[foobazi insertObject:f atIndex:i];
[self didChangeValueForKey:@"foobazi"];
this won't give you the granular details of what was changed. I'd
suggest implementing the version as listed in the docs.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.