用BOOL填充数组时发出警告

Cra*_*Dev 4 boolean objective-c nsmutablearray ios

我有这个代码:

BOOL booleanValue = TRUE;
[arrayZone replaceObjectAtIndex:indexZone withObject:booleanValue];
Run Code Online (Sandbox Code Playgroud)

这段代码给了我一个警告说:

incompatible integer to pointer conversion: 
sending BOOL to parameter of type 'id'

为什么?

Nyx*_*0uf 14

你需要打你BOOLNSNUmber这样的:

BOOL booleanValue = TRUE;
[arrayZone replaceObjectAtIndex:indexZone withObject:[NSNumber numberWithBool:booleanValue]];
Run Code Online (Sandbox Code Playgroud)

然后,要检索您的BOOL值,请使用boolValue以下方法将其取消装箱:

BOOL b = [[arrayZone objectAtIndex:index] boolValue];
Run Code Online (Sandbox Code Playgroud)