Der folgende Code stammt aus dem von Apple bereitgestellten LazyTableImages-Beispielcode (source here).Capture selbst in Block (Retain-Zyklen), nicht immer?
In ihrem Komplettierungsblock haben sie einen Verweis auf self, der einen Retain-Zyklus verursachen sollte ... Aber dafür bekomme ich keine Warnung in Xcode, während ich in ähnlichem Code von mir würde.
Ist das korrekt?
Vielleicht vermisse ich eine Feinheit davon.
- (void)startIconDownload:(AppRecord *)appRecord forIndexPath:(NSIndexPath *)indexPath
{
IconDownloader *iconDownloader = [self.imageDownloadsInProgress objectForKey:indexPath];
if (iconDownloader == nil)
{
iconDownloader = [[IconDownloader alloc] init];
iconDownloader.appRecord = appRecord;
[iconDownloader setCompletionHandler:^{
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
// Display the newly loaded image
cell.imageView.image = appRecord.appIcon;
// Remove the IconDownloader from the in progress list.
// This will result in it being deallocated.
[self.imageDownloadsInProgress removeObjectForKey:indexPath];
}];
[self.imageDownloadsInProgress setObject:iconDownloader forKey:indexPath];
[iconDownloader startDownload];
}
}
mögliches Duplikat von [Möglich, \ [self anyFunction \] in Blöcken ohne \ _ \ _ schwaches Objekt (iOS 5 + ARC) zu übergeben] (http://stackoverflow.com/questions/9003600/possible-to-pass- self-anyfunction-in-blocks-ohne-schwach-objekt-ios-5-arc), Sorry Daniel :) – Abizern
Sie sagen, dass es keine Warnung gibt, weil es mehr als eine Ebene im Zyklus gibt, @Abizer? –
Es gibt keine Warnung, da es keinen Retain-Zyklus gibt. – Abizern