• 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
[Workaround] NSArrayController 'contentSet' bound to managed object relationship
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Workaround] NSArrayController 'contentSet' bound to managed object relationship


  • Subject: [Workaround] NSArrayController 'contentSet' bound to managed object relationship
  • From: mmalcolm crawford <email@hidden>
  • Date: Wed, 15 Feb 2006 21:20:53 -0800


Summary:

If you bind the 'contentSet' of an array controller to the relationship of a managed object that implements KVC-compliant set accessor methods, these methods are not invoked.

You can workaround this bug by binding to selection.self.relationshipName instead of selection.relationshipName



Detail:

You typically modify a relationship in a managed object using the proxy returned by -mutableSetForKey:. NSKeyValueCoding (KVC) defines a pattern for mutator methods you can implement to customise proxy handling of an NSMutableSet property (see <http:// developer.apple.com/documentation/Cocoa/Reference/Foundation/ ObjC_classic/Protocols/NSKeyValueCoding.html#//apple_ref/occ/instm/ NSObject/mutableSetValueForKey:>). For example, given a schema:

	Department  <-- department -- employees ->> Employee

you could implement the following set mutator methods in a Department class:

- (void)addEmployeesObject:
and
- (void)removeEmployeesObject:

(as shown at <http://developer.apple.com/documentation/Cocoa/ Conceptual/CoreData/Articles/cdAccessorMethods.html#//apple_ref/doc/ uid/TP40002154-DontLinkElementID_5>).

If you use the set proxy directly, these methods are invoked correctly. For example:

NSMutableSet *employees = [aDepartment mutableSetValueForKey:@"employees"];
id anEmployee = [employees anyObject];
[employees removeObject:anEmployee];


would invoke 'removeEmployeesObject' on aDepartment.


If, however, you manipulate a relationship using an array controller in which the 'contentSet' is bound to a key path such as "selection.relationshipName" of another controller, the custom KVC set mutator methods are not invoked. For example, consider an interface like that illustrated in the NSPersistentDocument tutorial (<http://developer.apple.com/documentation/Cocoa/Conceptual/ NSPersistentDocumentTutorial/02_CreatingProj/ chapter_3_section_4.html>). An object controller manages a Department instance and an array controller manages the Department's 'employees' relationship. The array controller's 'contentSet' binding is bound to:


	[Department Object Controller].selection.employees

If you modify the content of the array controller using the add: or remove: methods, then the custom KVC set mutator methods are not invoked.


You can work around this bug by introducing 'self' into the keypath. The binding would therefore be:


	[Department Object Controller].selection.self.employees


mmalc

_______________________________________________
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


  • Prev by Date: Re: [NSTableView selectedRow] is always 0?
  • Next by Date: Re: Help, How to resize a window on cocoa
  • Previous by thread: NSPopupButton & Captured Display
  • Next by thread: Re: Help, How to resize a window on cocoa
  • Index(es):
    • Date
    • Thread