0
在下面的代碼我檢查陣列isKindOfClass
,但是當我檢查與它是否會真的兩個條件:CFArrayRef類使用iskindofclass
NSString *values[] = {@"hello", @"world"};
CFArrayRef arrayRef = CFArrayCreate(kCFAllocatorDefault, (void *)values, (CFIndex)2, NULL);
NSArray *array = (__bridge NSArray *)arrayRef;
if ([array isKindOfClass:[NSMutableArray class]]) {
NSLog(@"array is mutableArray");
}
if ([array isKindOfClass:[NSArray class]]) {
NSLog(@"array is immutabelArray");
}
結果:
2016-09-16 10:00:32.873 TestArray[12246:198137] array is mutableArray
2016-09-16 10:00:32.874 TestArray[12246:198137] array is immutabelArray
結果讓我迷惑 數組是不可變的,但爲什麼打印數組是可變的。
添加另一個日誌:'NSLog(@「array是%@」,[array class]);'。 – rmaddy
你應該也看到http://stackoverflow.com/questions/1788690/objective-c-how-to-check-if-variable-is-nsarray-or-nsmutablearray – rmaddy