Lil*_*ard 16
Objective-C没有类变量,你所谓的成员变量称为实例变量.可以在实例方法中按名称引用实例变量.如果您需要类变量的行为,则可以使用文件级静态.
这是一个非常快速的示例:
foo.h中
@interface Foo : NSObject {
NSString *foo;
}
@end
Run Code Online (Sandbox Code Playgroud)
Foo.m
static NSString *bar;
@implementation Foo
- (void)foobar {
foo = @"test"; // assigns the ivar
bar = @"test2"; // assigns the static
}
@end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15067 次 |
| 最近记录: |