我有一个数组,其中包含当前用户位置和一些注释引脚之间的距离。尽管第一个日志正确显示了值,但当我将它们添加到数组中时,所有值都是“0”。我究竟做错了什么?我已经提到了苹果文档。我没有任何错误。先感谢您..
for (Posts *post in allPosts) {
CLLocation *postLocation = [[CLLocation alloc] initWithLatitude:post.coordinate.latitude longitude:post.coordinate.longitude];
CLLocation *userLoc = [[CLLocation alloc] initWithLatitude:appDelegate.currentLocation.coordinate.latitude longitude:appDelegate.currentLocation.coordinate.longitude];
CLLocationDistance dist = [userLoc distanceFromLocation:postLocation];
distance = [NSString stringWithFormat:@"%.2f", dist];
NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:post, nil];
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:distance ascending:YES];
NSLog(@"%@", sort);
NSArray *sor = @[sort];
NSArray *sorted = [array sortedArrayUsingDescriptors:sor];
float flo = [[NSString stringWithFormat:@"%@",sorted]floatValue];
NSLog(@"%.f",flo);