• 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: getting the type of an object of a Dictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >getting the type of an object of a Dictionary (From: Salánki Benjámin <email@hidden>)

  • Prev by Date: Re: more NSEvent stuff
  • Next by Date: Re: Cocoa - Naive questions about memory
  • Previous by thread: Re: getting the type of an object of a Dictionary
  • Next by thread: NSDictionary displayed in NSBrowser or NSOutlineView
  • Index(es):
    • Date
    • Thread