• 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: Modifying the array of an NSArrayController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Modifying the array of an NSArrayController


  • Subject: Re: Modifying the array of an NSArrayController
  • From: René Puls <email@hidden>
  • Date: Fri, 7 Nov 2003 11:16:54 +0100

Hi all,

I just tried adding the (will|did)ChangeValueForKey: notifications as suggested by Henrik, and it solved my problem:

[self willChangeValueForKey:@"array"];
[array addObject:[NSDictionary dictionaryWithObject:@"New Item" forKey:@"string"]];
[self didChangeValueForKey:@"array"];

Seems like this is a basic misunderstanding of how key-value observing works.

Apparently the "owner" of the array--not the array itself--is responsible for notifying observers when new objects are added. Also, observers don't register with the array for changes, they register with the owner. The array will only notify me of changes to *specific* objects that it contains.

Subclassing NSArrayController and overriding newObject to initialize new objects seems rather complicated to me. I think Aaron Hillegass is right with his suggestion to add some delegate methods like arrayController:willAddNewObject: to NSArrayController.

http://cocoa.mamasam.com/COCOADEV/2003/11/1/76257.php

Anyway, I think I can work with this for now. Thanks everyone for your help!

I have one more question concerning KVO though. The documentation says this about automatic change notifications:

http://developer.apple.com/documentation/Cocoa/Conceptual/ KeyValueObserving/Concepts/AutoVsManual.html

Automatic key-value observing informs observers of all changes made through key-value compliant methods, the key-value coding methods, as well as directly assigning a value to an instance variable. The examples shown in Listing 3-1 result in any observers of the property name to be notified of the change.

From the examples:

// assigning an instance variable directly
name=[newSavingsName retain];

How can the run-time system notice a change to the actual instance variable? Isn't this just like accessing a memory location? I thought this was only possible using some kind of debugging technique, like a breakpoint?

Kind regards,
Rene Puls
_______________________________________________
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: Modifying the array of an NSArrayController
      • From: Henrik Wittland <email@hidden>
References: 
 >Modifying the array of an NSArrayController (From: René Puls <email@hidden>)
 >Re: Modifying the array of an NSArrayController (From: Henrik Wittland <email@hidden>)
 >Re: Modifying the array of an NSArrayController (From: René Puls <email@hidden>)
 >Re: Modifying the array of an NSArrayController (From: Scott Anguish <email@hidden>)
 >Re: Modifying the array of an NSArrayController (From: René Puls <email@hidden>)
 >Re: Modifying the array of an NSArrayController (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Re: Does pserver work from Xcode?
  • Next by Date: Controller Layer + array count + NSOutlineView
  • Previous by thread: Re: Modifying the array of an NSArrayController
  • Next by thread: Re: Modifying the array of an NSArrayController
  • Index(es):
    • Date
    • Thread