Re: getting the type of an object of a Dictionary
Re: getting the type of an object of a Dictionary
- Subject: Re: getting the type of an object of a Dictionary
- From: "Kenneth C. Dyke" <email@hidden>
- Date: Sun, 4 May 2003 23:06:04 -0700
On Sunday, May 4, 2003, at 10:30 PM, Salanki Benjamin wrote:
Hello,
is there a way to find out if an object for a given key of a
Dictionary is of a given type, say an NSString or an NSMutable
Dictionary?
Off the top of my head...
@interface NSDictionary(ClassChecking)
- (BOOL)objectForKey:(id)key isKindOfClass:(Class)theClass
@end
@implementation NSDictionary(ClassChecking)
- (BOOL)objectForKey:(id)key isKindOfClass:(Class)theClass
{
id object = [self objectForKey:key];
if(object)
return [object isKindOfClass:theClass];
else
return NO;
}
@end
...
if([myDictionary objectForKey:myKey isKindOfClass:[NSString class]])
...
Categories rule.
-Ken
Kenneth Dyke, email@hidden (personal), email@hidden (work)
Sr. Mad Scientist, MacOS X OpenGL Group, Apple Computer, Inc.
C++: The power, elegance and simplicity of a hand grenade.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.