在一个快速项目中,我能够轻松完成此任务。我有CLLocationCoordinate2D的数组和CLLocationDistances将null值添加到Objective-C中的数组中
这里是SWIFT代码(PFQuery内)当我尝试在目标C将它们添加到我得到的位置和距离阵列它工作得很好
if let returnedLocation = object["location"] as? PFGeoPoint
{
let requestLocation = CLLocationCoordinate2DMake(returnedLocation.latitude, returnedLocation.longitude)
self.locations.append(requestLocation)
let requestCLLocation = CLLocation(latitude: requestLocation.latitude, longitude: requestLocation.longitude)
let driverCLLocation = CLLocation(latitude: location.latitude, longitude: location.longitude)
let distance = driverCLLocation.distanceFromLocation(requestCLLocation)
self.distances.append(distance/1000)
}
一个错误,因为我添加了一个没有指针的对象。解决这个问题的最佳方法是什么?谢谢
Objective C的代码(他们都是NSMutableArrays)
if (object[@"driverResponded"] == nil) {
NSString *username = object[@"username"];
[self.usernames addObject:username];
PFGeoPoint *returnedLocation = object[@"location"];
CLLocationCoordinate2D requestLocation = CLLocationCoordinate2DMake(returnedLocation.latitude, returnedLocation.longitude);
//FIX!
[self.locations addObject:requestLocation];
CLLocation *requestCLLocation = [[CLLocation alloc]initWithLatitude:requestLocation.latitude longitude:requestLocation.longitude];
CLLocation *driverCLLocation = [[CLLocation alloc]initWithLatitude:location.latitude longitude:location.longitude];
CLLocationDistance distance = [driverCLLocation distanceFromLocation:requestCLLocation];
[self.distances addObject:distance/1000];
}
为什么不只是将'requestCLLocation'添加到'self.locations'并从中拉出'CLLocationCoordinate2D'当你需要它? – random
标题中指定的问题中没有'null'。 – Cristik