初始化bool数组 - 返回null

gar*_*hdn 0 arrays boolean objective-c ios

我在初始化一系列bool时遇到了很多问题.当使用NSLog我不断得到(null).我正在尝试设置piecesInPlace40个NO的可变数组.我试图改变setupArrayWithFalsesYES用于测试目的,并仍然得到(null).

BOOL setupArrayWithFalses = NO;
for (int i=0; i<40; i++) {
    [piecesInPlace addObject:[NSNumber numberWithBool:setupArrayWithFalses]];
}
NSLog(@"Value of object: %@", [piecesInPlace objectAtIndex:0]);
Run Code Online (Sandbox Code Playgroud)

Zal*_*ykr 5

你在初始化你的阵列吗?

piecesInPlace = [[NSMutableArray alloc] init];
Run Code Online (Sandbox Code Playgroud)