简体   繁体   English

无法从NSMutable数组存储和检索值

[英]Not able to store and retrieve values from NSMutable array

I'm storing a value in a NSMutableArray ...however when I try to retrieve it, it doesn't find it. 我将值存储在NSMutableArray ...但是,当我尝试检索它时,找不到它。

My aim is to look for beacon major id. 我的目的是寻找信标专业ID。 If a new beacon major id is found I save it in the array. 如果找到新的信标专业ID,则将其保存在阵列中。 So the next time when I read the beacon major id, if it is already present in the array I don't use it. 因此,下一次当我读取信标主ID时,如果它已经存在于数组中,我将不使用它。

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);
     }
}

More often than not, this happens if you've not initialized your NSMutableArray property before its put to use like so visitedBeaconsArrayMajor = [[NSMutableArray alloc] init]; 通常,如果您没有在NSMutableArray属性投入使用之前就初始化了NSMutableArray属性,就会发生这种情况,就像visitedBeaconsArrayMajor = [[NSMutableArray alloc] init]; resulting in it being nil . 导致它nil

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM