Search code examples
iosblockclass-method

ios When I create a class-method,it shows the error: Member reference base type 'Class' is not a structure or union


@interface A : UIView{
   NSInteger z_num;
}
+ (void)getNum;
@end
@implementation A
+ (void)getNum{
__weak typeof(self) weakSelf = self;
[[SingletonClass shareInstance] getNum:^(NSInteger status, NSString *num) {
    __strong typeof(weakSelf) strongSelf = weakSelf;
    if (strongSelf) {
        if (status == NET_OK) {
            strongSelf->z_num = [num integerValue]; //error:Member reference base type 'Class' is not a structure or union
        }
    }

}];
}

i tried to find some ways to fix this, but it didn't work, what should i do to fix this error?


Solution

  • When you're referencing self inside a class method, it's of type Class and not the instance of that class. That's why when you're doing a strongSelf it's trying to find an instance variable on that class, and not an object of that class.