我需要在objective-c 中使用一个 boolean 数组。我已经基本设置好了,但是编译器会在以下语句中抛出警告:
[updated_users replaceObjectAtIndex:index withObject:YES];
这是,我敢肯定,因为 YES 根本就不是一个对象;这是一个原始的。无论如何,我需要这样做,并且非常感谢有关如何完成它的建议。
谢谢。
最佳答案
没错,就是这样:NS* 容器只能存储 Objective-C 对象,不能存储原始类型。
你应该能够通过将它包装在一个 NSNumber 中来完成你想要的:
[updated_users replaceObjectAtIndex:index withObject:[NSNumber numberWithBool:YES]]
或使用 @(YES)
将 BOOL
包装在 NSNumber
[updated_users replaceObjectAtIndex:index withObject:@(YES)]]
然后就可以拉出boolValue了:
BOOL mine = [[updated_users objectAtIndex:index] boolValue];
关于c - Objective C boolean 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/628343/