Objective-C:标量属性的默认值是atomic吗? [英] Objective-C: Defaults to atomic for scalar properties?

查看:121
本文介绍了Objective-C:标量属性的默认值是atomic吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个朋友告诉我,标量属性(BOOL,NSInteger等)的@property默认值是非原子的.即

A friend told me that the @property default for scalar properties (BOOL, NSInteger, etc.) is nonatomic. I.e.,

@property BOOL followVenmo;

默认为

@property (nonatomic) BOOL followVenmo;

但是,我总是对默认值始终是原子的,标量的或非原子的印象始终如此.

But, I was always under the impression that the default is always atomic, scalar or not.

是哪个?

推荐答案

基于我对其他几个相关问题的研究:

Based on my research of a couple other related questions:

  • Objective-c properties for primitive types
  • Does atomic actually mean anything for a synthesized primitive?

我将遵守 @Rhubarb的建议:

根据经验,如果您不需要多线程支持-如果您使用的是UIViewControllers这样的UI代码,则通常不需要多线程支持,只需声明所有这些都是非原子的即可.

As a rule of thumb, if you don't need multithreaded support - which you generally don't if you're working in UI code like UIViewControllers, then just declare it all nonatomic.

这篇关于Objective-C:标量属性的默认值是atomic吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆