• 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 error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary error


  • Subject: Re: NSDictionary error
  • From: Jerrod Fowkes <email@hidden>
  • Date: Fri, 14 Apr 2006 06:04:19 -0700 (PDT)

Thank you for the replies: Here is what I have found:

Dan - The NSStringFromClass I didn't know about. Thank you for the heads up on that...It returned a "NSCFDictionary" as expected....when it goes to execute the next line "value = [[NSString alloc] initWithString...It still give me that error. It appears that the address I am getting back from the NSDictionary is of type NSCFDictionary and so it does not have a length attribute to copy the characters into value from initWithString. That is my guess. I don't think I am off but do tell me if I am. I would like to understand more.

Alan -
I think you are on to something here. yes result is an NSDictionary, I am going to see if the object at Key ksWSMethodInvocation* is a dictionary and see if I can get some key value pairs out of there. If I have troubles I will hollar.

Here is what I have found before I got your responses. I messed around some more and did this:

NSString* value;
value = [result objectForKey: (NSString*)kWSMethodInvocationResult];
NSString* value1;
value1 = [[NSString alloc] initWithFormat : @"%@", value];

value1 then holds the value that I need comming back from my web service. So, I would like to know this:

How come the description for the object that I am getting out of key KWSMethodInvocationResult is the actual value that I am looking for.

1)Is there some kind of default there that I don't know about ?!

2)How come initWithFormat appears to copy the contents of the object out as a string and initWithString doesn't even though I cast initWithString as a NSString?
Is it because I am actually initWithFormating the description of the oject that actually is a string rather than the object itself?

If anyone could shed some light on this...It would be greatly appreciated.

Alan Hart <email@hidden> wrote:
On 13 Apr 2006, at 20:07, Jerrod Fowkes wrote:

> Hi, I have been pounding away at this for awhile. I am fairly a
> newbie so bare with me:
>
> NSString* value;
> value = [[NSString alloc] initWithString: [result objectForKey:
> (NSString*) kWSMethodInvocationResult]];
>
> and I am getting this error:
>
> -[NSCFDictionart length]:selector not recognized
>
> [result objectForKey* returns a NSCFDictionary...which I am
> assuming to be a pointer to a NSDictionary Object. Well I would
> think that initWithString would be able to take that address and
> then copy the correct data out of the dictionary for the key
> kWSMethod*. What am I doing wrong here?

 From your description, the variable result appears to be a reference
to an NSDictionary containing a reference to another NSDictionary at
the key kWSMethodInvocationResult?

-initWithString: can only take an NSString* as its parameter. It's
trying to use the NSDictionary* returned by [result
objectForKey:kWSMethodInvocationResult] as if it were a NSString*,
and it's calling -length on it, and failing.

If [result objectForKey:kWSMethodInvocationResult] returns another
NSDictionary, then you can't pretend it's an NSString. You have to
extract the string you want from it using -objectForKey: with an
appropriate key for that dictionary.

BTW: Assuming result is an NSDictionary*, with
kWSMethodInvocationResult as a valid key, you don't need to cast
kWSMethodInvocationResult to an NSString*.

Alan

---------------------------------------------------------------------------
Hi Jerrod,

I'd check your assumptions:


NSString *value;
id obj = [result objectForKey: (NSString*) kWSMethodInvocationResult];
NSLog(@"Object is a %@", NSStringFromClass([obj class]));
value = [[NSString alloc] initWithString:(NSString *)obj];


Dan




---------------------------------
Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSDictionary error
      • From: Alan Hart <email@hidden>
References: 
 >Re: NSDictionary error (From: Alan Hart <email@hidden>)

  • Prev by Date: Re: NSDictionary error
  • Next by Date: cocoa and EOF
  • Previous by thread: Re: NSDictionary error
  • Next by thread: Re: NSDictionary error
  • Index(es):
    • Date
    • Thread