Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C ARC __weak variable reference triggers warning "__weak attribute cannot be specified on an automatic variable"

I've got an app (only ios5) that inside a method declares a weak variable used inside a block to reference an instance of a view controller.

 QRCodeViewController * __weak weakSelf = self;

The problem is that the compiler shows a warning saying:

__weak attribute cannot be specified on an automatic variable

In that application I've used a lot weak references and I never saw a warning like that, the only difference from the other classes is that this class is implemented in a .mm file since it uses a c++ object and project can't compile if I leave it as a .m.
I must say that the code seems to work fine.
Any suggestion?

like image 720
Andrea Avatar asked Aug 23 '12 09:08

Andrea


1 Answers

Facing this same warning, I make it disappear using a __block attribute the following way :

__block __weak MyViewController* weakSelf = self;
like image 173
Dalzhim Avatar answered Oct 08 '22 00:10

Dalzhim