0
這是我的方法爲什麼該屬性沒有在此方法中設置?
- (void)populateLocationsToSort {
//1. Get UserLocation based on mapview
self.userLocation = [[CLLocation alloc] initWithLatitude:self._mapView.userLocation.coordinate.latitude longitude:self._mapView.userLocation.coordinate.longitude];
//Set self.annotationsToSort so any new values get written onto a clean array
self.myLocationsToSort = nil;
// Loop thru dictionary-->Create allocations --> But dont plot
for (Holiday * holidayObject in self.farSiman) {
// 3. Unload objects values into locals
NSString * latitude = holidayObject.latitude;
NSString * longitude = holidayObject.longitude;
NSString * storeDescription = holidayObject.name;
NSString * address = holidayObject.address;
// 4. Create MyLocation object based on locals gotten from Custom Object
CLLocationCoordinate2D coordinate;
coordinate.latitude = latitude.doubleValue;
coordinate.longitude = longitude.doubleValue;
MyLocation *annotation = [[MyLocation alloc] initWithName:storeDescription address:address coordinate:coordinate distance:0];
// 5. Calculate distance between locations & uL
CLLocation *pinLocation = [[CLLocation alloc] initWithLatitude:annotation.coordinate.latitude longitude:annotation.coordinate.longitude];
CLLocationDistance calculatedDistance = [pinLocation distanceFromLocation:self.userLocation];
annotation.distance = calculatedDistance/1000;
//Add annotation to local NSMArray
[self.myLocationsToSort addObject:annotation];
**NSLog(@"self.myLocationsToSort in someEarlyMethod is %@",self.myLocationsToSort);**
}
//2. Set appDelegate userLocation
AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
myDelegate.userLocation = self.userLocation;
//3. Set appDelegate mylocations
myDelegate.annotationsToSort = self.myLocationsToSort;
}
在粗線,self.myLocationsToSort已經是空。我認爲將價值設定爲零基本上已經清理出來,準備好重新使用了?我需要這樣做,因爲此方法在啓動時調用一次,並且在從Web獲取數據時收到NSNotification後第二次。如果我再次從NSNotification選擇器調用此方法,新的Web數據將被寫入舊數據的頂部,並且它會產生不一致的值::)
的「垃圾收集」的一提的是錯在這裏。 ARC不以任何方式涉及垃圾收集。 –
@KenThomases它是什麼?只需在refcount = 0時自動刪除對象? –
是的,它是參考計數的內存管理。 ARC只是自動化保留和發佈。 –