c - Objective C boolean 数组

我需要在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/

相关文章:

iphone - 将长格式的 NSString 拆分为多行

objective-c - 使用自动布局自定义纵横比

iphone - iOS 7 表格 View 无法自动调整内容插入

objective-c - 'pod install' 不会更新现有的 pod

iphone - 将 HEX NSString 转换为 NSData

objective-c - 通过指针运算与 C 中的下标访问数组值

ios - 将 NSInteger 转换为 NSIndexpath

iphone - UITableView/UITableViewCell 点击事件响应?

objective-c - 恢复 iOS7 之前的 UINavigationController p

ios - 为什么我的 UIButton 的 "touch up inside"事件没有被调用?