Objective C的布尔数组 [英] Objective C Boolean Array
问题描述
我需要利用在Objective-C布尔值的数组。我知道了大多成立,但是编译器在下面的语句抛出一个警告:
I need to utilize an array of booleans in objective-c. I've got it mostly set up, but the compiler throws a warning at the following statement:
[updated_users replaceObjectAtIndex:index withObject:YES];
这是,我敢肯定,是因为根本就没有一个对象;这是一个原始的。无论如何,我必须这样做,而且会大大AP preciate就如何完成它的意见。
This is, I'm sure, because YES is simply not an object; it's a primitive. Regardless, I need to do this, and would greatly appreciate advice on how to accomplish it.
感谢。
推荐答案
是的,这正是它是什么:对NS *容器只能存储目标-C对象,而不是原始类型
Yep, that's exactly what it is: the NS* containers can only store objective-C objects, not primitive types.
您应该能完成你想要的东西在一个NSNumber包裹起来:
You should be able to accomplish what you want by wrapping it up in an NSNumber:
[updated_users replaceObjectAtIndex:指数withObject:[NSNumber的numberWithBool:YES]
或使用 @(YES)
其中封装了 BOOL
在的NSNumber
[updated_users replaceObjectAtIndex:指数withObject:@(YES)]
您可以再拉出boolValue:
You can then pull out the boolValue:
BOOL矿= [[updated_users objectAtIndex:指数] boolValue];
这篇关于Objective C的布尔数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!