• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: valueForKeyPath
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: valueForKeyPath


  • Subject: Re: valueForKeyPath
  • From: Jim Puls <email@hidden>
  • Date: Thu, 30 Apr 2009 18:28:32 -0700

On Apr 30, 2009, at 5:29 PM, Ulai Beekam wrote:


Because just adding a key to a dictionary does not make it key-value- coding compliant with respect to that key. KVC is needed for key paths like that to work.



----------------------------------------
From: email@hidden
To: email@hidden
Date: Thu, 30 Apr 2009 19:00:51 -0500
Subject: valueForKeyPath

Folks;

I have a mutable dictionary 'myPerson' which has a key=@"address".
The object stored at @"address" is another mutable dictionary.

someCity = [myPerson valueForKeyPath:@"address.city"] --> nil

someCity = [[myPerson valueForKey:@"address"] valueForKey:@"city"] --
expected value

Why does -valueForKeyPath not work in this circumstance?

Steve

Check it:

$ irb
>> require 'osx/cocoa'
=> true
>> include OSX
=> Object
>> d1 = NSMutableDictionary.dictionaryWithObject_forKey("test", "foo")
=> #<NSCFDictionary {#<NSCFString "foo">=>#<NSCFString "test">}>
>> d2 = NSMutableDictionary.dictionaryWithObject_forKey(d1, "bar")
=> #<NSCFDictionary {#<NSCFString "bar">=>#<NSCFDictionary {#<NSCFString "foo">=>#<NSCFString "test">}>}>
>> d2.valueForKeyPath("bar")
=> #<NSCFDictionary {#<NSCFString "foo">=>#<NSCFString "test">}>
>> d2.valueForKeyPath("bar.foo")
=> #<NSCFString "test">


Appears to work just fine. Are you sure something else isn't different than you expect?

-> jp

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

References: 
 >valueForKeyPath (From: Steve Cronin <email@hidden>)
 >RE: valueForKeyPath (From: Ulai Beekam <email@hidden>)

  • Prev by Date: Re: NSScanner off-by-one and I can't see why...
  • Next by Date: question about mutable vs. non-mutable
  • Previous by thread: RE: valueForKeyPath
  • Next by thread: Re: valueForKeyPath
  • Index(es):
    • Date
    • Thread