I have a number of methods in blocks, firing one inside the next, in order to sync some data with a web service. Most of these behave completely fine, but one method won't let me mention self
after it's been called, giving me a capturing self strongly in this block is likely to lead to a retain cycle
warning.
Here's what I mean:
[self deleteEntriesCorrespondingToDeletedNotesInNotebook:notebook success:^{
[self deleteNotesToMatchDeletedEntriesWithCompletion:^{
[self deleteResourcesToMatchDeletedMediaItemsWithCompletion:^{
[self addOrUpdateEntriesCorrespondingToUpdatedNotesInNotebook:notebook success:^{
//Anything calling a property or self after this point is a problem and gives the warning
[self addOrUpdateNotesCorrespondingToUpdatedEntriesWithCompletion:^{
}];
}failure:^{
}];
}];
}];
}failure:^{
}];
Any ideas why only items passed this point have a problem with this? If I replace the method before it with another similar method, there isn't a problem. The problem is only existent after addOrUpdateEntriesCorrespondingToUpdatedNotesInNotebook:
is used.
[self deleteEntriesCorrespondingToDeletedNotesInNotebook:notebook success:^{
[self deleteNotesToMatchDeletedEntriesWithCompletion:^{ //this line here and the rest in your downward loop
dont use self. Instead do this before the first line
__typeof__(self) __weak _weakSelf = self;
and then from second line onwards, replace self
with weakSelf
try this. cheers
All of your methods could "behave fine" or create a retain cycle, depending on what they do with the completion block.
As explained here: Blocks retain cycle from naming convention? , the clang compiler uses naming conventions to decide whether to emit a warning or not: All methods add...
and set...
(but not addOperationWithBlock
!) cause a warning, other methods don't.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.