• 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 07:42:10 -0700 (PDT)

Ironically, somehow it is a dictionary. here is what I have found:

you can do this:

[txtoutput setStringValue: [result objectForKey: (NSString*) kWSMethodInvocationResult]];

and that will print something like "{GetStringValue = "Testing1212"}"
where "Testing1212" is the value that I actually return from the service.
GetStringValue is actually the key into the dictionary.

So I can do this:

NSDictionary* dict;
dict = [result objectForKey: (NSString*)kWSMethodInvocationResult];

//dict now has a 1 key value pair;
NSArray* keys;
keys = [dict allKeys];

NSString* keyName
keyName = [keys objectAtIndex: 0]; //This will display my keyName in the gdb

NSArray* values;
values = [dict allValues];

NSString* value;
value = [values objectAtIndex: 0]; //This will display the value.

The description for the object at kWSInvocationResult is a NSCFDictionary. I can't run this code...even if I cast it like so :

value = [[NSString alloc] initWithString: (NSString*)[result
objectForKey: (NSString*) kWSMethodInvocationResult]];

It has a problem because NSCFDictionary doesn't have a length. So you initial post was correct. somehow it's a dictionary I am getting back...which is ok because I better understand things now.

comments / questions would be greatly appreciated. -Jerrod Fowkes Thank you again.

Alan Hart <email@hidden> wrote:
On 14 Apr 2006, at 14:04, Jerrod Fowkes wrote:
> 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];

OK, I wasn't familiar with the WebServices API so I looked up
kWSMethodInvocationResult. As far as I can see, assuming result is
the NSDictionary* that is produced by WSMethodInvocationInvoke(),
then value already contains the string you want. It's not a
dictionary, so ignore my previous suggestion.

> 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.

Why *shouldn't* [result objectForKey:KWSMethodInvocationResult] be
the value you're looking for? Why are you trying to process it
further if it's already the string you want?

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

No.

> 2)How come initWithFormat appears to copy the contents of the
> object out as a string and initWithString doesn't..

I'm guessing it's because the items in the CFDictionary returned by
WSMethodInvocationInvoke() are not Cocoa objects, they are
CoreFoundation structures, and you have to cast the objectForKey: to
an NSString before you can use it to initWithString. If so your
original code:

value = [[NSString alloc] initWithString: [result objectForKey:
(NSString*) kWSMethodInvocationResult]];

.... should have contained an extra cast:

value = [[NSString alloc] initWithString: (NSString*)[result
objectForKey: (NSString*) kWSMethodInvocationResult]];

  I'm not sure what you mean by "... I cast initWithString as a
NSString". You can't, and didn't, cast the method as a string.

-- Alan




---------------------------------
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

References: 
 >Re: NSDictionary error (From: Alan Hart <email@hidden>)

  • Prev by Date: Re: NSDictionary error
  • Next by Date: Re: cocoa and EOF
  • Previous by thread: Re: NSDictionary error
  • Next by thread: NSTextAttachmentCell as rollover in NSTextView?
  • Index(es):
    • Date
    • Thread