lundi 30 mars 2015

iOS Objective-C: weakSelf Syntax

Nearly every example of the weakSelf pattern I encounter online has the syntax



__weak typeof(self) weakSelf = self;


But the compiler complains about this syntax in the latest version of Xcode, requiring:



__weak __typeof__(self) weakSelf = self;


Did the syntax change, or am i missing an import? I tried pulling in <objc/runtime.h> but no change.


Stealthy bonus question: Why not just cast it explicitly?



__weak MyBoffoClass *weakSelf = self;


I found one answer here that said it was better to cast it directly, but no reasoning as to why.


Aucun commentaire:

Enregistrer un commentaire