WeakSelf/StrongSelf dance: __strong needed?

I read today in the Swift book:


__weak typeof(self) weakSelf = self;
self.block = ^{
   __strong typeof(self) strongSelf = weakSelf;
   [strongSelf doSomething];
}
// Excerpt From: Apple Inc. “Using Swift with Cocoa and Objective-C (Swift 3.1).”


When I saw '__strong' I got a bit concerned - in the past I had always used "typeof(self) strongSelf = weakSelf;, think the typeof made strongSelf strong.


Yikes! Did I get it wrong all these years???

I don't think you got it wrong. If 'typeof(self)' does not include the __weak/__strong attribute, then your usual declaration had no explicit attribute, and so defaulted to __strong.


OTOH, if 'typeof(self)' does include or imply the attribute, it must mean __strong, so your usual declaration was necessarily __strong.

Yes you got it wrong all these years. As we speak there are little pieces of memory floating around draining electricity all over the world causing the planet to marginally warm as we speak. Our children will live sadder lives because you didn't use weakSelf, thanks a lot.

WeakSelf/StrongSelf dance: __strong needed?
 
 
Q