Key-value observing and NSMutableArray
Key-value observing and NSMutableArray
- Subject: Key-value observing and NSMutableArray
- From: Dustin Voss <email@hidden>
- Date: Sat, 8 Nov 2003 13:59:42 -0800
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.
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"];
Will this work, too? How significant are the differences between this
and the "willChange:valuesAtIndexes:forKey:" implementation?
_______________________________________________
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.