Re: Confused with Chapter 7 in Hillegass' book (2nd ed.)
Re: Confused with Chapter 7 in Hillegass' book (2nd ed.)
- Subject: Re: Confused with Chapter 7 in Hillegass' book (2nd ed.)
- From: mmalcolm crawford <email@hidden>
- Date: Wed, 28 Jul 2004 17:32:56 -0700
On Jul 28, 2004, at 4:56 PM, Shalev NessAiver wrote:
The NSArrayController object is used in conjunction with Cocoa
bindings. When the NSArrayController is bound to a specific property of
an object, it can both access and set the data that it is bound to. The
way it does this is by calling two methods in the class that
NSArrayController is bound to: (your class must implement these
methods)
(Just for Scott's benefit...) No it doesn't *have* to implement these
methods. All that is required is that your container object be
key-value coding compliant for the key. Minimally you might just have
the property:
NSArray * employees;
KVC accessors will get and set the value appropriately. For many
people, however, this smacks of breaking encapsulation, or they want to
put custom logic into their accessor methods, in which case you might
implement:
- (NSMutableArray *)employees
{
return employees;
}
and
- (void)setEmployees:(NSArray *)newEmployees
{
[employees autorelease];
employees = [newEmployees copy];
}
If you are making frequent modifications to the array, and in
particular if the array is large, however, this pattern is inefficient
-- to make a modification (insert or delete) you must copy and replace
the whole array. In this case you should implement the indexed
accessors:
<
http://developer.apple.com/documentation/Cocoa/Conceptual/
KeyValueCoding/Concepts/AccessorConventions.html#//apple_ref/doc/uid/
20002174/BAJEDEFB>
See:
"Indexed Accessor Patterns for To-Many Properties"
mmalc
_______________________________________________
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.