Replacing __weak when not using ARC

I have this line of code:

__weak NSBlockOperation *weakOperation = operation; 

which causes this compiler error:

 __weak attribute cannot be specified on automatic variable. 

The reason for this is that I do not support ARC (not yet ready to make a switch). Therefore, from another StackOverFlow question, I was recommended to use:

 __unsafe_unretained NSBlockOperation *weakOperation = operation; 

Because of what, the error disappears, but for context I use it, it does not work (see this question if it is interesting: How to cancel NSOperationQueue ).

So my question is, can I replace the __weak keyword in this case to get rid of this warning? Everything works correctly when I use __weak , but I am afraid that it will not be delayed in future versions of iOS.

+4
source share
1 answer

You should not worry about future versions of iOS, because __weak is what the compiler interprets when creating the code for you.

Looking at your other post, I suggest that your goal is to avoid weakOperation , despite the link from within the block. In your specific case, when you are not using ARC, you can replace __weak with __block to indicate that your variable should not be saved during capture.

Note that the effect of __block behavior on retain is different from ARC and manual save counting.

+7
source

All Articles