Ios 无法从NSMutable数组中存储和检索值
我正在NSMutableArray中存储一个值…但是当我尝试检索它时,它没有找到它 我的目标是查找信标主id。如果找到新的信标主id,我将其保存在数组中。所以下次当我读取信标主id时,如果它已经存在于数组中,我不会使用它Ios 无法从NSMutable数组中存储和检索值,ios,objective-c,arrays,nsmutablearray,estimote,Ios,Objective C,Arrays,Nsmutablearray,Estimote,我正在NSMutableArray中存储一个值…但是当我尝试检索它时,它没有找到它 我的目标是查找信标主id。如果找到新的信标主id,我将其保存在数组中。所以下次当我读取信标主id时,如果它已经存在于数组中,我不会使用它 for (int i=0; i<numberOfBeacondsInRange; i++) { NSLog(@"Processing current beacon: %d of %d", i, numberOfBeacondsInRange-1);
for (int i=0; i<numberOfBeacondsInRange; i++)
{
NSLog(@"Processing current beacon: %d of %d", i, numberOfBeacondsInRange-1);
ESTBeacon *currentBeacon = [self.beaconsArray objectAtIndex:i];
// not able to retrive values from the array to compare
BOOL isPresent=NO;
for (int j=0; j<100; j++)
{
if ([visitedBeaconsArrayMajor objectAtIndex:j] == currentBeacon.major)
{
NSLog(@"Already seen");
isPresent=YES;
}
}
if (isPresent==NO)
{
[visitedBeaconsArrayMajor addObject:currentBeacon.major];
NSLog(@"Add major:%@",currentBeacon.major);
}
}
通常情况下,如果在NSMutableArray属性投入使用之前没有初始化它,则会发生这种情况,如VisitedBeaconArrayMajor=[[NSMutableArray alloc]init];结果是零 您是否分配/初始化visitedBeaconsArrayMajor?首先检查NSLog@%@,visitedBeaconsArrayMajor;如果为空,则应分配一个数组