Re: String Comparison and return values
Re: String Comparison and return values
- Subject: Re: String Comparison and return values
- From: Rainer Brockerhoff <email@hidden>
- Date: Tue, 26 May 2009 10:25:10 -0300
At 01:06 -0700 26/05/09, email@hidden wrote:
>From: Thomas Davie <email@hidden>
>To: John Ku <email@hidden>
>References: <email@hidden>
> <email@hidden>
> <email@hidden>
> <email@hidden>
> <email@hidden>
> <email@hidden>
>In-Reply-To: <email@hidden>
>Date: Tue, 26 May 2009 10:04:15 +0200
>Message-ID: <email@hidden>
>
>Op 26 May 2009, om 09:56 heeft John Ku het volgende geschreven:
>
>>Oh so the very first return value from a Dictionary is not actually a
>>string?
>>NSString *itemA = [DictionaryA valueForKey:@"FirstProcessIdentifier"];
>>
>>I've check the apple document, valueForKey returns an ID... so it return an
>>object? how do I proceed?
>>If i cast it as NSString it gives me an error.
>
>Simple - sort your type error out! The dictionary contains at least one number. This means that either you're creating it wrong, or you're trying to get values out of it wrong...
>
>In the latter case you might want to try something like
>
>id item = [dictionaryA valueForKey:@"FirstProcessIdentifier"];
>
>if ([item isKindOfClass:[NSString class]])
>{
> // do stuff
>}
>else if ([item isKindOfClass:[NSNumber class]])
>{
> // do other stuff
>}
>...
It appears that one of the items can be an NSString and the other an NSNumber, so none of the standard comparisons will work directly.
Instead of testing what kind of class each is, I'd try something like
if ([itemA intValue] == [itemB intValue]) ...
since both NSString and NSNumber will respond to intValue, that should work.
--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
Weblog: http://www.brockerhoff.net/bb/viewtopic.php
_______________________________________________
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