本文介绍了默认情况下,Objective-C中的私有ivars是否具有原子属性(如属性)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一种情况,我有一些这样的实例变量.

Consider a scenario where I have some instance variable like this.

@implementation Foo {
    NSString *foo;
}

// Some code 

@end

我想知道这个foo ivar在默认情况下是否是原子的?它的行为类似于在此类的@interface中创建的属性(我有)吗?

I wanted to know if this foo ivar would be atomic by default? Does it behave similar to a property (had I) created in the @interface of this class?

有人能启发我以这种方式创建的ivar的默认属性是什么吗?

Can someone enlighten me as to what are the default attributes of an ivar created in such a manner?

推荐答案

不,不会.这是使用@property声明而不是ivar的(许多)原​​因之一.使用@property声明,您将在幕后为您编写一个实际的 accessor方法,并且默认情况下这是原子的.

No, it would not. That is one of the (many) reasons for using a @property declaration instead of an ivar. With a @property declaration, you get an actual accessor method written for you behind the scenes, and this will be atomic by default.

这篇关于默认情况下,Objective-C中的私有ivars是否具有原子属性(如属性)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 22:07