我需要在objective-c中使用一个布尔array.我基本上已经设置好了,但是编译器在下面的语句中抛出了一个警告:
[updated_users replaceObjectAtIndex:index withObject:YES];
我敢肯定,这是因为"是"根本不是一个对象;这是原始的.无论如何,我需要这样做,并将非常感谢有关如何实现它的建议.
谢谢
我需要在objective-c中使用一个布尔array.我基本上已经设置好了,但是编译器在下面的语句中抛出了一个警告:
[updated_users replaceObjectAtIndex:index withObject:YES];
我敢肯定,这是因为"是"根本不是一个对象;这是原始的.无论如何,我需要这样做,并将非常感谢有关如何实现它的建议.
谢谢
没错,就是这样:NS*容器只能存储objective-C对象,不能存储基本类型.
您应该能够通过将其包装在NSNumber中来实现您想要的:
[updated_users replaceObjectAtIndex:index withObject:[NSNumber numberWithBool:YES]]
或者使用@(YES)
将BOOL
包裹在NSNumber
中
[updated_users replaceObjectAtIndex:index withObject:@(YES)]]
然后,您可以拉出布尔值:
BOOL mine = [[updated_users objectAtIndex:index] boolValue];