Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 用布尔填充数组时发出警告_Objective C_Ios_Nsmutablearray_Boolean - Fatal编程技术网

Objective c 用布尔填充数组时发出警告

Objective c 用布尔填充数组时发出警告,objective-c,ios,nsmutablearray,boolean,Objective C,Ios,Nsmutablearray,Boolean,我有以下代码: BOOL booleanValue = TRUE; [arrayZone replaceObjectAtIndex:indexZone withObject:booleanValue]; 这段代码给了我一个警告,上面写着: incompatible integer to pointer conversion: sending BOOL to parameter of type 'id' 不兼容的整数到指针转换: 正在将BOOL发送到“id”类型的参数 为什么?您只能在NSAr

我有以下代码:

BOOL booleanValue = TRUE;
[arrayZone replaceObjectAtIndex:indexZone withObject:booleanValue];
这段代码给了我一个警告,上面写着:

incompatible integer to pointer conversion: sending BOOL to parameter of type 'id' 不兼容的整数到指针转换: 正在将BOOL发送到“id”类型的参数
为什么?

您只能在
NSArray
中存储对象,而不能存储基本类型


干杯

你需要用一个
NSNUmber
框住你的
BOOL
,如下所示:

BOOL booleanValue = TRUE;
[arrayZone replaceObjectAtIndex:indexZone withObject:[NSNumber numberWithBool:booleanValue]];
然后,要检索
BOOL
值,请使用
boolValue
取消装箱:

BOOL b = [[arrayZone objectAtIndex:index] boolValue];

这个问题似乎是重复的


本质上,BOOL是一种基本类型-您必须将其包装在对象中以消除警告。

BOOL是一种基本类型,您的数组需要一个对象。这就是为什么你需要把它写进一个数字里。但对于较新的xcode,您只需键入@YES或@NO,xcode就会将其视为一个数字Withbool。 因此,不是:

    BOOL booleanValue = TRUE;
    [arrayZone replaceObjectAtIndex:indexZone withObject:[NSNumber numberWithBool:booleanValue]];
您现在可以使用

    [arrayZone replaceObjectAtIndex:indexZone withObject:@YES];