objective-c - Objective C 属性变量和非属性变量的存储

标签 objective-c variables object properties storage

任何人都可以澄清我,变量到底存储在 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/

相关文章:

ios - 是否可以设置 UITextField deleage 并将其委托(delegate)设置为自身?

javascript - 如何使用ajax将javascript变量传递给php

javascript - 从 namles 对象中检索单独的信息

c# - 单例模式——创建对象

jquery - 过滤jquery中的对象

ios - UITableViewCell 上的 UILabel 显示不正确

ios - 根据要求将应用程序数据与 iCloud 同步

ios - ScrollView 中的多个图像

java - 一条线上的多个分配未按预期工作

c++ - 计算器程序 Xcode 错误 '@' 标记前的预期表达式