Re: NSArray NSDictionary Tree Q.
Re: NSArray NSDictionary Tree Q.
- Subject: Re: NSArray NSDictionary Tree Q.
- From: Ian McGregor <email@hidden>
- Date: Sun, 14 Dec 2003 07:54:15 -0800
Well I have not been able to try in in 10.2 yet, it does work when I
use the 10.2.7 SDK in xcode. Makes me wonder how many other "10.3"
goodies I have not put to good use!
Cheers,
Ian
On 13-Dec-03, at 11:18 PM, Scott Anguish wrote:
>
hmmm... no, I vaguely remember adding that. It could be newly doc'd
>
there because of the oddities as far as when/where things are
>
documented. valueForKey: isn't new though.
>
>
if you have a 10.2 install try using valueForKey: on an NSDictionary
>
(or can someone?) or just try valueForKeyPath:.. you can do that with
>
a trivially small command line tool..
>
>
(it's difficult to keep straight what worked when, especially given
>
that internally we run things much earlier than external developers...
>
sorry that I can't be more precise)
>
>
>
>
On Dec 14, 2003, at 2:06 AM, Ian McGregor wrote:
>
>
> Hi Scott,
>
>
>
> In my docs for NSDictionary it reads:
>
>
>
> valueForKey:
>
>
>
> - (id)valueForKey:(NSString *)key
>
>
>
> Returns the result of sending objectForKey: to the receiver.
>
>
>
> Availability
>
>
>
>
>
> Available in Mac OS X v10.3 and later.
>
>
>
> See Also: setValue:forKey: (NSMutableDictionary)
>
>
>
>
>
> A mistake perhaps??
>
>
>
> Cheers,
>
>
>
> Ian
>
>
>
>
>
> On 13-Dec-03, at 10:44 PM, Scott Anguish wrote:
>
>
>
>> valueForKey: and valueForKeyPath have been around for quite a while,
>
>> and aren't new for 10.3
>
>>
>
>> You can determine the version of the OS that a method is available
>
>> for by looking at the reference docs.. those that are new (since
>
>> 10.2.6 I think) are noted as such...
>
>>
>
>>
>
>> On Dec 13, 2003, at 8:01 PM, Ian McGregor wrote:
>
>>
>
>>> Thanks Aaron.
>
>>>
>
>>> Unfortunately the app has to run on 10.2.x, and as I understand it
>
>>> (now) the valueForKey is a new 10.3 only thing. Thanks for the
>
>>> explanation of it though. It actually makes more sense now!
>
>>>
>
>>> Cheers,
>
>>>
>
>>> Ian
>
>>>
>
>>> On 13-Dec-03, at 4:30 PM, Aaron Tuller wrote:
>
>>>
>
>>>> if i understand you correctly, yes, use Key Value Coding, it's
>
>>>> already implemented on NSDictionary.
>
>>>>
>
>>>> say you now write something like this:
>
>>>>
>
>>>> [[[someDict objectForKey:@"key1"] objectForKey:@"key2"]
>
>>>> objectForKey:@"key3"]
>
>>>>
>
>>>> you can do:
>
>>>>
>
>>>> [someDict valueForKeyPath:@"key1.key2.key3"];
>
>>>>
>
>>>> where the keypath is any NSString, you could store it externally
>
>>>> or generate it at runtime.
>
>>>>
>
>>>> and there's also
>
>>>>
>
>>>> - (void)takeValue:(id)value forKeyPath:(NSString *)key;
>
>>>>
>
>>>> so you could set the value at a certain path.
>
>>>>
>
>>>> check out:
>
>>>>
>
>>>> http://developer.apple.com/documentation/Cocoa/Conceptual/
>
>>>> KeyValueCoding/index.html
>
>>>>
>
>>>> if this isn't what you're asking, sorry for the noise.
>
>>>>
>
>>>> -aaron
>
>>>>
>
>>>> At 10:01 AM -0800 12/13/03, Ian McGregor wrote:
>
>>>>> I have an immutable NSArray containing a tree-like data structure.
>
>>>>>
>
>>>>> NSArray *rootItems
>
>>>>> - NSDictionary item
>
>>>>> - NSDictionary item
>
>>>>> - NSDictionary item
>
>>>>>
>
>>>>> each NSDictionary item contains an NSArray *children, which can
>
>>>>> contains even more NSDictionary *item objects.
>
>>>>>
>
>>>>> Basically a tree using NSArray and NSDictionary
>
>>>>>
>
>>>>> My model requires these objects to be stored in an immutable
>
>>>>> fashion,
>
>>>>> but I make a mutable copy when I am altering the data, no dramas
>
>>>>> or
>
>>>>> probs there.
>
>>>>>
>
>>>>> The problem I am having, is finding an easier method the traverse
>
>>>>> the
>
>>>>> "nodes" or NSDictionary *item's to change their values.
>
>>>>>
>
>>>>> For example, if am currently using unique id's for the group
>
>>>>> nodes, and
>
>>>>> another set of unique id's for the object nodes. I have had some
>
>>>>> success using various recursive methods to locate the nodes I
>
>>>>> wish to
>
>>>>> change, but actually changing the node is confusing me.
>
>>>>>
>
>>>>> Any suggestions?
>
>>>>> _______________________________________________
>
>>>>> 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.
>
>>> _______________________________________________
>
>>> 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.
>
>> _______________________________________________
>
>> 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.
_______________________________________________
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.