属性变量和非属性变量的存储

属性变量和非属性变量的存储

本文介绍了Objective C 属性变量和非属性变量的存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以澄清一下,objective c 中存储的变量究竟在哪里?

Can anyone please clarify me that where exactly the variables stored in 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"是私有的(因为其他类通常不#import .m文件).

"string", "textg", "number" and "numb" are instance variables to the class. The difference is that "string" and "number" are eligible to be publicly accessible (via ref->number), and "textg" and "numb" are private (since other classes conventionally do not #import .m files).

mURL"和sURL"属性存储为实例变量_mURL"和_sURL".同样,_mURL"有资格被公开访问(通过 ref->_mURL),而_sURL"不是出于同样的原因.

"mURL" and "sURL" properties are stored as instance variables "_mURL" and "_sURL". Again, "_mURL" is eligible to be publicly accessible (via ref->_mURL), and "_sURL" is not for the same reason.

而且,常量"是一个存储在堆上的普通全局变量.

And, "constant" is an ordinary global variable stored on the heap.

这篇关于Objective C 属性变量和非属性变量的存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 05:09