I have the following action for a button, which toggles whether an object is shown as favorite or non-favorite:
- (IBAction)addToFavorites:(UIButton *)sender {
if ([object isFavorite]) {
[_apiManager removeFromFavorite:[object ID] withCompletion:^ {
[_favoriteButton setImage:[UIImage imageNamed:@"favorite"] forState:UIControlStateNormal];
}];
}
else {
[_apiManager addToFavorite:[object ID] withCompletion:^ {
[_favoriteButton setImage:[UIImage imageNamed:@"favorite_yellow"] forState:UIControlStateNormal];
}];
}
}
Both completion blocks are identical, with exception to the image name.
XCode is giving to the else
case the warning: Capturing 'self' strongly in this block is likely to lead to a retain cycle
and pointing at _favoriteButton
.
However, the same does not happen in the case when the if
condition is true.
I imagine that either both or none of the cases should present the warning, and I don't understand why only the later shows it. Is this an Xcode bug? Are both causing retain cycles?