我需要帮助。我需要一个可用于我应用程序中的每个函数的变量
@interface A()
@property (assign) CGFloat x;
@end
@implementation
@synthesize x = _x;
-(void)DidLoad
{ ...
self.x = 1.0; }
-function1
{ CGFloat y;
y = x;
NSString *string = [NSString stringWithFormat:"%f", y];
NSLog(@"%@", string);
}
但是"y"是空变量!你能帮助初学者吗?
在函数 1 中,您应该使用:
y = self.x;
y = _x; //this should work too, but it's not recommended to access the variable that way.