The __block attribute when releasing an instance variable.

When compiling the Objective-C class, I found the following error:

VideoView.h:7: error: __block attribute can be specified on variables only

Also here is an important part of the header file:

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface VideoView :UIView{
@private
    __block AVPlayer *player;   
}
...

Is there any explanation why g ++ believes that I am applying the __block attribute to an object without a variable?

+3
source share
1 answer

You cannot have __blockan instance variable, as this is completely optional.

Namely, when you do:

^{
     someIvar = ....;
 }();

The block captures an immutable, stored reference to selfand indirectly refers to iVar through this, and thus does __blocknothing, since the variable is neither constant nor readonly.

, , ARC " " iVar.

. , , , ( ), ARC / LLVM .

+13

All Articles