• 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
Key-value observing and NSMutableArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.
  • Follow-Ups:
    • Re: Key-value observing and NSMutableArray
      • From: Scott Anguish <email@hidden>
  • Prev by Date: Palm Desktop User Data
  • Next by Date: Re: Palm Desktop User Data
  • Previous by thread: Re: Palm Desktop User Data
  • Next by thread: Re: Key-value observing and NSMutableArray
  • Index(es):
    • Date
    • Thread