ios When I create a class-method,it shows the error: Member reference base type 'Class' is not a structure or union
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
}
}
}];
}
我试图找到一些方法来解决这个问题,但是没有用,我应该怎么做才能解决这个错误?
当您在 class 方法中引用 self
时,它的类型是 Class
而不是 class 的实例。这就是为什么当你在做 strongSelf
时,它试图在 class 上找到一个实例变量,而不是 class.
的对象
@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
}
}
}];
}
我试图找到一些方法来解决这个问题,但是没有用,我应该怎么做才能解决这个错误?
当您在 class 方法中引用 self
时,它的类型是 Class
而不是 class 的实例。这就是为什么当你在做 strongSelf
时,它试图在 class 上找到一个实例变量,而不是 class.