I understand WHY we will use weakSelf in a block, just not so much.
I am converting a codebase to ARC, which gives a lot of warnings to the save cycle with blocks. From the documentation I compiled, I need to change this:
[self.selectedAsset addToFavoritesWithCompletion:^(NSError *error) { self.selectedAsset.isFavorite = YES; [self updateIsFavoriteButton]; }];
:
__weak MyViewController* weakSelf = self; [self.selectedAsset addToFavoritesWithCompletion:^(NSError *error) { self.selectedAsset.isFavorite = YES; [weakSelf updateIsFavoriteButton]; }];
To make the compiler happy and avoid holding loops. My question is: why is there no need to change the line:
self.selectedAsset.isFavorite = YES;
use weakSelf? Does this evaluate the method invocation method? Why does the compiler not warn about strings in this format?
[[self selectedAsset]setIsFavorite:YES];
EDIT: I am just upgrading to Xcode 4.6, and now it only generates compiler warnings for this situation. Funny time :)
Vaporwarewolf
source share