这是我收到此错误时的原始代码
类A.h
+(ClassA*)methodA:(NSData*)data;
@property (nonatomic, strong) NSMutableArray *arr; @property (nonatomic, strong) RXMLElement *rxmlRoot;
@结尾
类A.m
+(ClassA*)methodA:(NSData*)data {
//NSLog(@"class is %@",[name class]); ClassA *ClassA = [[Stores alloc] init]; arr = [NSMutableArray array]; rxmlRoot = [RXMLElement elementFromXMLData:data];
}
我正在审查我的代码,现在我有两个选项来修复代码
选项A
类A.h
+(ClassA*)methodA:(NSData*)data; @property (nonatomic, strong) NSMutableArray *arr; @property (nonatomic, strong) RXMLElement *rxmlRoot; @end
类A.m
+(ClassA*)methodA:(NSData*)data { //NSLog(@"class is %@",[name class]); ClassA *ClassA = [[Stores alloc] init]; ClassA.arr = [NSMutableArray array]; <----- this has been modified ClassA.rxmlRoot = [RXMLElement elementFromXMLData:data];<----- this has been modified }
选项B
类A.h
+(ClassA*)methodA:(NSData*)data; @end
类A.m
static RXMLElement *rxlRoot; <----- this has been added as class variable static NSMutableArray *arr; <----- this has been added as class variable +(ClassA*)methodA:(NSData*)data { //NSLog(@"class is %@",[name class]); ClassA *ClassA = [[Stores alloc] init]; arr = [NSMutableArray array]; rxmlRoot = [RXMLElement elementFromXMLData:data];
}
我尝试了 optionA 或 optionB 并且编译器没有抱怨任何东西并且代码正常工作。
我在 optionB 之后看到许多创建类变量的帖子。
问题:当我们处理类方法和类变量时,optionA 也是一个很好的方法吗?
请就这个问题给我建议,顺便说一下,如果我在某处犯了错误,请纠正我。谢谢