2012-01-16 27 views
3

在下面的字典,我想寫的類型類的條件,有沒有什麼辦法在iteraction如何檢查一類在NSDictionary中

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"); 
     } 

    } 

注單獨標識類型:我想單一條件檢查值[WebService類],[任務類],[操作類]

回答

1

找到答案在下面的鏈接

Check if object is Class type

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 (class_isMetaClass(object_getClass(obj))) { 
      NSLog(@"Getting In"); 
     } 

    } 
2
- (BOOL)isMemberOfClass:(Class)aClass 

這是什麼ü可能尋求。

例如,在這個代碼,isMemberOfClass:將返回NO:

NSMutableData *myData = [NSMutableData dataWithCapacity:30]; 
id anArchiver = [[NSArchiver alloc] initForWritingWithMutableData:myData]; 
if ([anArchiver isMemberOfClass:[NSCoder class]]) 
    //something... 

裁判:http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html


編輯:

在NSDictionaries你將不得不把字符串鍵。我建議你將該類轉換爲一個字符串,並將其作爲關鍵字。

要使用類的一個關鍵是不可能的方式。

+0

它是用來要檢查一個特定的班級,我只想要generi ℃溶液來檢查一個類是否其單獨 – Nakkeeran 2012-01-16 11:15:18

+0

請檢查我的更新問題 – Nakkeeran 2012-01-16 11:21:01

+0

@Nakkeeran:您要使用的類作爲一個關鍵的方式是不可能的,我建議一個變通使用方法在我的答案是關鍵。 – 2012-01-16 11:30:10

8

查找-isKindOfClass:和-isMemberOfClass:

if([object isKindOfClass:[AObjectClass class]) 
{ 
    NSLog(@"object is of type AObjectClass"); 
} 

見我的問題Apple isKindOfClass: documentation.

+0

它是用來檢查一個特定的類,我只想通用的解決方案,以檢查其是否一類單獨 – Nakkeeran 2012-01-16 11:17:00

+0

請檢查我的更新問題 – Nakkeeran 2012-01-16 11:21:11