@符号在objective

编程入门 行业动态 更新时间:2024-10-24 19:24:35
@符号在objective-c中代表什么?(What does the @ symbol represent in objective-c?)

我正在学习目标c并继续碰到@符号。 它在不同的场景中使用,例如在字符串的开头或合成访问器方法。

目标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.

What's does the @ symbol mean in objective-c?

最满意答案

在C或C ++标识符中不使用@字符,因此用于以不会与其他语言关键字冲突的方式引入Objective-C语言关键字。 这使得语言的“目标”部分可以自由地与C或C ++部分混合。

因此,除了很少的例外,任何时候在某些Objective-C代码中看到@ ,您正在查看Objective-C构造而不是C或C ++构造。

主要的例外是id , Class , nil和Nil ,它们通常被视为语言关键字,即使它们后面也有一个typedef或者#define 。 例如,编译器实际上根据它适用于声明的指针类型转换规则,以及是否生成GC写入障碍的决定,特别对待id 。

其他例外是in , out , inout , oneway , byref和bycopy ; 这些用作方法参数和返回类型的存储类注释,以使分布式对象更高效。 (它们成为运行时可用的方法签名的一部分,可以查看以确定如何最佳地序列化事务。)还有@property声明, copy , retain , assign , readonly , readwrite , nonatomic , getter和setter getter ; 这些仅在@property声明的属性部分中有效。

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.

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.

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.

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.

更多推荐

本文发布于:2023-07-27 17:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1293569.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:符号   objective

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!