不同self.myIvar和myIvar? [英] Different between self.myIvar and myIvar?
本文介绍了不同self.myIvar和myIvar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在objective-c类中引用实例变量的区别在于:
self.myIvar
和
myIvar
如果它已被声明为标题中的属性并合成?
$如果你引用self.myVar,它将使用你的头文件中声明的@property。$ b
$ b
例如
@property(nonatomic,retain)Class * myClass;
$ b b
如果您有
myClass = [[Class alloc] init ....];
保留计数 1
但如果您使用
self.myClass = [Class alloc] init ....]; p>
由于retain属性,保留计数 2 >
这是相同的,如果你设置setter || getter方法在@property中。
What's the difference between referring to an instance variable in an objective-c class as this:
self.myIvar
and
myIvar
if it's been declared as a property in the header and synthesized?
解决方案If you refer to self.myVar, it will use the @property declared in your header file.
For example
@property(nonatomic, retain) Class *myClass;If you have
myClass = [ [ Class alloc ] init .... ];Retain Count will be 1 But if you use
self.myClass = [ [ Class alloc ] init .... ];Retain Count will be 2 because of the retain property.
It's the same if you set setter || getter method in the @property.
这篇关于不同self.myIvar和myIvar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文