无法设置属性,CLLocation

时间:2014-06-01 11:43:59

标签: ios objective-c cllocationmanager cllocation

我正在尝试使用以下代码设置自定义类的CLLocation属性(名为objectLocation),从我的主ViewController调用。不幸的是,我收到一条错误,告诉我"评论"表示"表达式不可分配。" locationsArray是自定义类的对象数组。我真的需要设置这个值,所以感谢任何帮助!

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
for (int i = 0; i < [locationsArray count]; i++) {

if ([locationsArray[i] objectLocation] == NULL) {
    [locationsArray[i] objectLocation] = [locations lastObject]; //retrieves most recent location data - THIS IS THE LINE THAT RECEIVES THE ERROR
    //now set up a region and start monitoring data for that region
    [locationsArray[i] region] = [[CLRegion alloc]
                                          initCircularRegionWithCenter:
                                          [[locationsArray[i] objectLocation] coordinate]
                                                                radius:2
                                                            identifier:[NSString stringWithFormat:@"%@", [locationsArray[i] objectLocationName]]];
       }
}
}

1 个答案:

答案 0 :(得分:1)

如果它是您班级中CLLocation的属性,并且假设您的locationsArray拥有该对象且您的locations数组确实包含CLLocation个对象,请尝试以下内容:

((<YOUR_CLASS>*)[locationsArray[i]).objectLocation = [locations lastObject]; 

希望这有帮助。