• 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: Notification when changes occur to an array?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Notification when changes occur to an array?


  • Subject: Re: Notification when changes occur to an array?
  • From: Mattias Arrelid <email@hidden>
  • Date: Wed, 27 Sep 2006 15:43:48 +0200

It sounds like you don't want a notification really. Use Key Value Observing instead. That will tell you when an item is added or removed from the array, and even what the new/old objects are.

KVO seems more appropriate, I agree on that! Thanks for pointing me in the right direction.


I'm still having some difficulties grasping how I'm supposed to get it working though. I have a simple class with an NSMutableArray, called "spotlights". If I want to observe changes to it's count, I assume I'm supposed to have the following two methods in my class (the class that contains the array):

- (void)registerObservers
{
	[spotlights addObserver: self
				forKeyPath: @"count"
				   options: NSKeyValueObservingOptionNew
				   context: NULL];
}

- (void)observeValueForKeyPath:(NSString *)keyPath
					  ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context
{

    if ([keyPath isEqual:@"count"]) {
		NSLog(@"The count did change.");
    }
}

Btw, I call "registerObservers" in my init method of my class.

When running the example, the application exits due to SIGNAL 5 (SIGTRAP). This is what follows:

2006-09-27 15:36:35.835 Prototype[4163] An uncaught exception was raised
2006-09-27 15:36:35.835 Prototype[4163] [<NSCFArray 0x350f00> addObserver:forKeyPath:options:context:] is not supported. Key path: count
2006-09-27 15:36:35.835 Prototype[4163] *** Uncaught exception: <NSInvalidArgumentException> [<NSCFArray 0x350f00> addObserver:forKeyPath:options:context:] is not supported. Key path: count


This sounds like the NSMutableArray isn't completely KVO? Like there is no method for setting a new count? Or am I wrong? *confused*

Thanks on advance
/ Mattias
_______________________________________________
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


  • Follow-Ups:
    • Re: Notification when changes occur to an array?
      • From: Julio Cesar Silva dos Santos <email@hidden>
    • Re: Notification when changes occur to an array?
      • From: Hank Heijink <email@hidden>
References: 
 >Notification when changes occur to an array? (From: Mattias Arrelid <email@hidden>)
 >Re: Notification when changes occur to an array? (From: Mike Abdullah <email@hidden>)

  • Prev by Date: Re: detecting mouseDrag event in NSView
  • Next by Date: Re: SFCertificateView incorrectly indicates cert expiration sometimes
  • Previous by thread: Re: Notification when changes occur to an array?
  • Next by thread: Re: Notification when changes occur to an array?
  • Index(es):
    • Date
    • Thread