• 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: NSDictionary & KVC problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary & KVC problem


  • Subject: Re: NSDictionary & KVC problem
  • From: Nathan Dumar <email@hidden>
  • Date: Sun, 24 Oct 2004 18:42:34 -0400

Ah hah! I think you're right, that it's making a dictionary of one key and one value, each an array of the keys and values. I was following the docs:

public NSDictionary(NSArray objects,
NSArray keys)
Creates an NSDictionary with entries from the contents of the keys and objects NSArrays. This method steps through objects and keys, creating entries in the new dictionary as it goes. Each key object and its corresponding value object is added directly to the dictionary.


So why did it not do that?

Here's my code:

prefs = new NSDictionary(thisUser.preferences().valueForKey("value"), thisUser.preferences().valueForKey("name"));

or equally (I tried both):

NSArray values = new NSArray(thisUser.family().preferences().valueForKey("value"));
NSArray names = new NSArray(thisUser.family().preferences().valueForKey("name"));
prefs = new NSDictionary(values, names);


Thanks,
Nathan


On Oct 24, 2004, at 5:13 AM, Ben Ketteridge wrote:

On Sat, 23 Oct 2004 20:27:11 -0400, Nathan Dumar <email@hidden> wrote:
I have an NSDictionary called "prefs." I've loaded it with pairs of
strings, as follows:

prefs.allKeys() yields (("idNum", "uF1", "archiveTo", "uF2", "uF3",
"histLimit"))

prefs.allValues() yields (("numOnly", "Field 1", "", "Field 2", "Field
3", "8"))

So, when I do prefs.valueForKey("uF1") I should get "Field 1", but I
don't. I get null. In fact, I get null for any of the keys. When
bound to a WOString (value = prefs.uF1) it's the same problem. What am
I doing wrong?

Are the (( an artifact of the way you've presented the data in your email, or are they part of what toString outputs?

If the former, I don't know what you've done wrong, but if it's the
latter, it would appear there is only one key in the dictionary, and
that is the array ("idNum", "uF1", "archiveTo", "uF2", "uF3",
"histLimit") and there is one value in the dictionary, and that is the
array ("numOnly", "Field 1", "", "Field 2", "Field 3", "8").

Creating the NSDictionary can be done like this:
NSDictionary dict = new NSDictionary(new Object[] {
    "idNum", "uF1", "archiveTo", "uF2", "uF3", "histLimit"
}, new Object[] {
    "numOnly", "Field 1", "", "Field 2", "Field 3", "8"
});

try this and see if dict.valueForKey("uF1") still gives null.

HTH,
Ben
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSDictionary & KVC problem
      • From: Art Isbell <email@hidden>
References: 
 >NSDictionary & KVC problem (From: Nathan Dumar <email@hidden>)
 >Re: NSDictionary & KVC problem (From: Ben Ketteridge <email@hidden>)

  • Prev by Date: Re: Hashtable to WOString?
  • Next by Date: Re: NSDictionary & KVC problem
  • Previous by thread: Re: NSDictionary & KVC problem
  • Next by thread: Re: NSDictionary & KVC problem
  • Index(es):
    • Date
    • Thread