永远不会读取在初始化期间存储到'beaconsData'的值

时间:2015-04-20 14:00:41

标签: ios objective-c memory-leaks

我将"值存储到' beaconsData'在初始化期间永远不会读取"标记行的消息,我不太明白为什么会发生这种情况。

- (void)locationManager:(KTKLocationManager *)locationManager didRangeBeacons:(NSArray *)beacons
{
    //NSLog(@"Ranged beacons count: %lu", [beacons count]);
    _beaconKontaktArr = [[NSMutableArray alloc] init];

    for (CLBeacon *beacon in beacons) {
        NSDictionary *beaconsData = [[NSDictionary alloc] init]; //problem is there
        KTKBeacon *beaconData = [self _getDataForBeacon:beacon];
        if (beaconData)
        {
            beaconsData = @{@"beacon": beacon, @"ktkBeacon": beaconData};

            [_beaconKontaktArr addObject:beaconsData];
        }
    }
}

1 个答案:

答案 0 :(得分:0)

在定义从未使用过的变量时,将对象添加到beaconsData,然后在if循环中用新数据覆盖空字典。该变量应该移动到循环内部。

- (void)locationManager:(KTKLocationManager *)locationManager didRangeBeacons:(NSArray *)beacons {
    _beaconKontaktArr = [[NSMutableArray alloc] init];

    for (CLBeacon *beacon in beacons) {
        KTKBeacon *beaconData = [self _getDataForBeacon:beacon];
        if (beaconData) {
            NSDictionary *beaconsData = @{@"beacon": beacon, @"ktkBeacon": beaconData};
            [_beaconKontaktArr addObject:beaconsData];
        }
    }
}