3

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.

Nate Birkholz
  • 2,739
  • 4
  • 20
  • 29
  • 1
    Reasonable looking answer here: http://stackoverflow.com/questions/14877415/difference-between-typeof-typeof-and-typeof-objective-c – danh Mar 31 '15 at 00:32
  • Thanks, I searched for typeof but didn't get that result, clearly should have dug deeper, thank you. – Nate Birkholz Mar 31 '15 at 01:56

1 Answers1

0

After the help from @danh pointing me at Difference between typeof, __typeof and __typeof__ (Objective-c), I discovered the issue was in the compiler settings.

Click on the project at the top of the Project Navigator window, click on Build Settings, and choose to View All: Choosing Settings

Next scroll down to Apple LLVM n.n - Language and examine the settings: Language Settings

In my case, the language dialect was set to C99, which doesn't support the GNU compiler macros and other extensions to the C language.

Not sure why it's set like this for the project (the project architect doesn't recall why), I just have to allow for the fact in my reading of StackOverflow code snippets. Better than introducing something by changing it because I am a lazy typist.

Community
  • 1
  • 1
Nate Birkholz
  • 2,739
  • 4
  • 20
  • 29