At 01:06 -0700 26/05/09, cocoa-dev-requ...@lists.apple.com wrote: >From: Thomas Davie <tom.da...@gmail.com> >To: John Ku <john.c...@gmail.com> >References: <b93d6f300905260033m5b840210t7510a0d5ee5fa...@mail.gmail.com> > <298ad53c-ec5e-4519-bbba-61a13ca9c...@bigpond.com> > <b93d6f300905260042r780fccaeoda12eb0c69016...@mail.gmail.com> > <b93d6f300905260046y45cdeadn2576cd3c1142a...@mail.gmail.com> > <7e0b7c90-a346-431f-8220-c8eccafd9...@mac.com> > <b93d6f300905260056q3b75362v40bb6c19a4fbd...@mail.gmail.com> >In-Reply-To: <b93d6f300905260056q3b75362v40bb6c19a4fbd...@mail.gmail.com> >Date: Tue, 26 May 2009 10:04:15 +0200 >Message-ID: <11f773a4-ad73-423c-847a-2d5fa8f80...@gmail.com> > >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 <rai...@brockerhoff.net> 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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com