Re: Who Calls Accessors in Bookmarks?
Re: Who Calls Accessors in Bookmarks?
- Subject: Re: Who Calls Accessors in Bookmarks?
- From: "Shawn Erickson" <email@hidden>
- Date: Thu, 30 Aug 2007 15:49:29 -0700
On 8/30/07, Gordon Apple <email@hidden> wrote:
> I've been studying the Bookmarks example and trying to lift code for
> Drag and Drop in tables.
Helps to give context on which example (or a link) but I am going to
assume you are talking about
<http://homepage.mac.com/mmalc/CocoaExamples/Bookmarks.zip>.
> What I don't understand is why the document has a
> set of name-specific accessors for the array. My code doesn't seem to need
> such.
Why? Well likely as an example to show you how to support things like
this in a way that allows your storage to be as you want (ignore the
fact that the storage in this case is just a serialized mutable
array).
> Furthermore, I don't understand how these accessors are getting called
> when "Add" and "Remove" buttons are clicked (yes, they trip breakpoints)
> since these are connected to the controller add/remove and I can't find any
> code or bindings that call the above named accessors.
<file:///Developer/ADC Reference Library/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/AccessorConventions.html#//apple_ref/doc/uid/20002174>
"You can also support to-many relationships by implementing the
indexed accessor methods for those properties. These methods make it
possible to support key-value coding for to-many relationships where
the related objects aren't stored in an array. Implementing indexed
accessors methods for a property makes that property indistinguishable
from an array when using key-value coding methods.
Supporting to-many relationships in this manner requires that your
class implement two methods using the naming pattern -countOf<Key> and
-objectIn<Key>AtIndex:. The -countOf<Key> method returns the number of
objects in the to-many relationship as an unsigned integer. The
-objectIn<Key>AtIndex: method returns the object at the specified
index in the to-many relationship."
...
"The key-value coding methods mutableArrayValueForKey: and
mutableArrayValueForKeyPath: provide mutable access to a to-many
relationship, regardless of the class used to model the relationship.
In order to support these methods, your class must implement two
additional methods for each of these keys:
-insertObject:in<Key>AtIndex: and -removeObjectFrom<Key>AtIndex:. The
-insertObject:in<Key>AtIndex: method is passed the object to insert,
and an unsigned int that specifies the index where it should be
inserted. The -removeObjectFrom<Key>AtIndex: method is passed an
unsigned int value specifying the index of the object to be removed
from the relationship. The example in Listing 6 shows the methods
required to support mutableArrayValueForKey: for the to-many
transactions property."
-Shawn
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden