In the below dictionary I want to write a condition for type class, Is there any way to identify the class type alone in the iteraction
NSDictionary *dictionary = [NSDictionary dictionaryWithKeysAndObjects:@"check",@"checkValue",@"webservice", [webservice class], @"list",@"listValue", nil, @"task", [task class], @"new", @"newValue", @"operation",[operation class]];
for(NSString *aKey in dictionary) {
if ([[dictionary valueForKey:aKey]) {
NSLog(@"Getting In");
}
}
Note :I want a single condition to check values [webservice class],[task class],[operation class]
Look up -isKindOfClass: and -isMemberOfClass:
if([object isKindOfClass:[AObjectClass class])
{
NSLog(@"object is of type AObjectClass");
}
See the Apple isKindOfClass: documentation.
- (BOOL)isMemberOfClass:(Class)aClass
this is what u seek probably.
For example, in this code, isMemberOfClass: would return NO:
NSMutableData *myData = [NSMutableData dataWithCapacity:30];
id anArchiver = [[NSArchiver alloc] initForWritingWithMutableData:myData];
if ([anArchiver isMemberOfClass:[NSCoder class]])
//something...
ref: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html
Edit:
In NSDictionaries you will have to put Strings for keys. I suggest you convert the class to a string with NSStringFromClass([MyClass class]);
and put that as a key.
The way you want to use the class as a key is impossible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With