任何人都可以澄清我,变量到底存储在 Objective C 中的位置吗?
在.h文件中
@interface example: NSObject
{
NString *string; // where is this stored
int number; // where is this stored
}
@property (nonatomic,strong) NSURL* mURL; // where is this stored
@end
同样,
在.m文件中
# import "xyz.h"
NSString *constant = @"hello"; // where is this stored
@interface example()
{
NString *textg; // where is this stored
int numb; // where is this stored
}
@property (nonatomic,strong) NSURL* sURL; // where is this stored
@end
最佳答案
“string”、“textg”、“number”和“numb”是该类的实例变量。区别在于“string”和“number”可以公开访问(通过 ref->number),而“textg”和“numb”是私有(private)的(因为其他类通常不会 #import .m 文件)。
“mURL”和“sURL”属性存储为实例变量“_mURL”和“_sURL”。同样,“_mURL”可以公开访问(通过 ref->_mURL),而“_sURL”则不能出于同样的原因。
并且,“constant”是存储在堆上的普通全局变量。
关于objective-c - Objective C 属性变量和非属性变量的存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27773335/