I was searching a bit about the difference between __weak
and __block
- What is the difference between a __weak and a __block reference?
To ARC or not to ARC? What are the pros and cons?
and found that if I am using ARC, I should use
__weak
references in blocks.
My old code was something like this:
__block GWTSDemandContactsController *safeMe = self;
[GWTSService getSuggestedContactsForDemand:self.demand success:^(NSArray *contacts) {
safeMe.activityLoading.hidden = true;
[safeMe setContactsForView:contacts];
} failure:^(NSError *error) {
safeMe.activityLoading.hidden = true;
}];
Then when I migrated to use ARC, I started using __weak
and also found out that I could use typeof(self)
This is very simple, so that I don't have to write the name of the class every time I want to save the self
reference. So now my code looks like this:
__weak typeof(self) safeMe = self;
But why do we avoid the *
here? Shouldn't it be a reference to self
? What are we storing here by avoiding the *
?
I don't know if I am missing something or not, but I could not understand this.