@符号在Objective-C中代表什么? [英] What does the @ symbol represent in objective-c?
问题描述
我正在学习Objective-c,并不断碰到@符号.它用于不同的场景,例如,在字符串开头或用于综合访问器方法.
I'm learning objective-c and keep bumping into the @ symbol. It is used in different scenarios, for example at the start of a string or to synthesise accessor methods.
Objective-c中的@符号是什么意思?
What's does the @ symbol mean in objective-c?
推荐答案
@
字符未在C或C ++标识符中使用,因此它以不冲突的方式引入了Objective-C语言关键字与其他语言的关键字一起使用.这样一来,该语言的目标"部分就可以与C或C ++部分自由地混合在一起.
The @
character isn't used in C or C++ identifiers, so it's used to introduce Objective-C language keywords in a way that won't conflict with the other languages' keywords. This enables the "Objective" part of the language to freely intermix with the C or C++ part.
因此,几乎没有例外,每当您在某些Objective-C代码中看到@
时,您都在看的是Objective-C结构而不是C或C ++结构.
Thus with very few exceptions, any time you see @
in some Objective-C code, you're looking at Objective-C constructs rather than C or C++ constructs.
主要例外是id
,Class
,nil
和Nil
,尽管它们后面也可能带有typedef
或#define
,但它们通常被视为语言关键字.例如,编译器实际上确实根据对声明使用的指针类型转换规则以及是否生成GC写障碍的决定来特别对待id
.
The major exceptions are id
, Class
, nil
, and Nil
, which are generally treated as language keywords even though they may also have a typedef
or #define
behind them. For example, the compiler actually does treat id
specially in terms of the pointer type conversion rules it applies to declarations, as well as to the decision of whether to generate GC write barriers.
其他例外是in
,out
,inout
,oneway
,byref
和bycopy
;这些用作方法参数和返回类型的存储类批注,以使分布式对象更有效. (它们成为运行时可用的方法签名的一部分,DO可以查看这些签名以确定如何最好地序列化事务.)@property
声明,copy
,retain
,assign
中还包含属性. ,readonly
,readwrite
,nonatomic
,getter
和setter
;这些仅在@property
声明的属性部分内有效.
Other exceptions are in
, out
, inout
, oneway
, byref
, and bycopy
; these are used as storage class annotations on method parameter and return types to make Distributed Objects more efficient. (They become part of the method signature available from the runtime, which DO can look at to determine how to best serialize a transaction.) There are also the attributes within @property
declarations, copy
, retain
, assign
, readonly
, readwrite
, nonatomic
, getter
, and setter
; those are only valid within the attribute section of a @property
declaration.
这篇关于@符号在Objective-C中代表什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!