我试图在一个连续运行的函数中创建一个 NSMutableArray ,并且只初始化一次它的值,这样它就不会在重复调用函数时继续初始化值(从而替换更改的值)。我的问题是,当我尝试在 if 语句中初始化值时,数组中的值不会改变,当我期望它打印“值为 1”时,它会继续打印“值为 0”
这是我的相关代码:
@property (nonatomic, strong) NSMutableArray * shapeMarked;
@synthesize shapeMarked;
//locationManager is the function that's continuously called
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
//event count is an integer that continuously increases by one each time the
//parent function is called, this if statement is used so that it only happens
//once
if(eventcount == 1){
for (int i = 0; i < 5; i++){
BOOL b = YES;
[shapeMarked addObject:[NSNumber numberWithBool:b]];
NSLog(@"value is %d", [[shapeMarked objectAtIndex:i] boolValue] );
}
}
}