【问题标题】:CFArrayRef class use iskindofclassCFArrayRef 类使用 iskindofclass
【发布时间】:2016-09-16 02:25:49
【问题描述】:

在以下代码中,我使用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

结果让我很困惑 数组是不可变的,为什么打印数组是可变的。

【问题讨论】:

标签: ios objective-c nsmutablearray nsarray


【解决方案1】:

如果您阅读 Apple 文档,您会看到 @interface NSMutableArray<ObjectType> : NSArray<ObjectType> 所以如果你的对象是一种 NSMutableArray,它肯定是一种 NSArray。 你应该检查NSLog(@"array class %@", [array class]);

【讨论】:

  • 我的问题是一个 NSArray 对象,它被确定为一个 NSMutableArray
猜你喜欢
  • 2014-09-18
  • 1970-01-01
  • 2014-07-24
  • 1970-01-01
  • 1970-01-01
  • 2010-11-08
  • 1970-01-01
  • 2014-10-13
  • 1970-01-01
相关资源
最近更新 更多