Re: Can a subclass of NSDictionary do this?
Re: Can a subclass of NSDictionary do this?
- Subject: Re: Can a subclass of NSDictionary do this?
- From: Chris Hanson <email@hidden>
- Date: Wed, 23 Jul 2003 18:24:02 -0500
On Wednesday, July 23, 2003, at 04:14 PM, p3consulting wrote:
How would KVC know (a) what types
of intermediate path items to create and (b) how to go about creating
them (i.e. what the designated initializer is etc.)?
by definition intermediate path items class is derived from the path
expression
(in the context of NSDictionary extensions - NOT of KVC related to
scripting of course)
Intermediate item class is *not* derived from the path expression.
That's part of the beauty of Key-Value Coding. The key path "a.b.c"
does nothing to imply that "a.b" is a dictionary, only that it responds
to -valueForKey:.
Now if you have full NSClassDescription objects for all of the model
objects involved you can use that information to find the type of "a.b"
-- and you can also probably determine this information via the
Objective-C runtime -- but you're still left with the question of how
to best construct intermediate objects.
Some of us routinely use key paths to traverse relationships between
objects, sometimes in a very automated fashions. (E.g. browser views,
table column identifiers, key paths stored in NSOutlineView items,
BDQualifier & BDRuleEngine.) Some of us even do things like use KVC to
traverse a dictionary containing objects rather than other dictionaries.
Fundamentally I think it's important that KVC *not* make assumptions
about the types of objects you want to work with in some cases. Either
it should be able to make an assumption universally (for instance that
an object responds to -valueForKey:) or it should not make it at all.
a.b.c -> implies a and b are NSDictionary, c can be anything
No, this is the equivalent of
[[a valueForKey:@"b"] valueForKey:@"c"]
with no assumptions about type at all.
a.b[1].c -> a is a NSDictionary, b is NSArray , c can be anything
No, this (if it worked) would be the equivalent of
[[a valueAtIndex:1 inPropertyWithKey:@"b"] valueForKey:@"c"]
with no assumptions about type at all.
And so on.
-- Chris
--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Mac OS X Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
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.