Re: Why can't I use any object as a key in a dictionary?
Re: Why can't I use any object as a key in a dictionary?
- Subject: Re: Why can't I use any object as a key in a dictionary?
- From: Alexander Spohr <email@hidden>
- Date: Mon, 1 Feb 2010 17:00:45 +0100
Am 01.02.2010 um 16:35 schrieb Charles Jenkins:
> On 2010-02-01 03:26, Roland King wrote:
>>
>> By the way, CALayer is a KVC compliant class so you can in fact just store a reference to an arbitrary object in it with
>>
>> [ layer setValue:value forKey:@"KeyForObjectAssociatedWithLayer" ];
>
> Roland, I'm a noob and I'm not sure I've got a good handle on KVC yet... This statement really looks interesting to me, because it seems to suggest that with a KVC-compliant class, you can make arbitrary linkages by just making up keys.
This is a wrong assumption.
Most classes are KVC compliant but you can not invent keys. You just use existing keys - properties and methods.
> (I checked the documentation, and haven't found any property named objectAssociatedWithLayer, so I'm assuming that you were able to create this key name yourself and name it whatever you liked.) Is this true or have I totally misunderstood you?
Read "Core Animation Extensions To Key-Value Coding" to get some enlightenment ;)
"Both CALayer and CAAnimation are key-value coding compliant container classes, allowing you to set values for arbitrary keys. That is, while the key “foo” is not a declared property of the CALayer class, however you can still set a value for the key “foo” as follows:"
The important thing is, that they are container classes. Like NSDictionary.
This is not true for all classes.
atze
_______________________________________________
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