在objective-c中@符号代表什么?

人气:678 发布:2022-10-16 标签: 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.

主要的例外是 idClassnilNil,它们通常被视为语言关键字,即使它们后面也可能有 typedef#define.例如,编译器实际上确实对 id 进行了特殊处理,它适用于声明的指针类型转换规则,以及是否生成 GC 写屏障的决定.

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.

其他例外是​​ inoutinoutonewaybyref, 和 bycopy;这些用作方法参数和返回类型的存储类注释,以使分布式对象更高效.(它们成为运行时可用的方法签名的一部分,DO 可以查看它以确定如何最好地序列化事务.)@property 声明中还有属性,copyretainassignreadonlyreadwritenonatomic、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.

148