Type Encodings
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html#//apple_ref/doc/uid/TP40008048-CH100-SW1
To assist the runtime system, the compiler encodes the return and argument types for each method in a character string and associates the string with the method selector. The coding scheme it uses is also useful in other contexts and so is made publicly available with the @encode() compiler directive. When given a type specification, @encode() returns a string encoding that type. The type can be a basic type such as an int, a pointer, a tagged structure or union, or a class name—any type, in fact, that can be used as an argument to the C sizeof() operator.
char *buf1 = @encode(int **); |
char *buf2 = @encode(struct key); |
char *buf3 = @encode(Rectangle); |
The table below lists the type codes. Note that many of them overlap with the codes you use when encoding an object for purposes of archiving or distribution. However, there are codes listed here that you can’t use when writing a coder, and there are codes that you may want to use when writing a coder that aren’t generated by @encode(). (See the NSCoder class specification in the Foundation Framework reference for more information on encoding objects for archiving or distribution.)
|
Code |
Meaning |
|---|---|
|
|
A |
|
|
An |
|
|
A |
|
|
A
|
|
|
A |
|
|
An |
|
|
An |
|
|
An |
|
|
An |
|
|
An |
|
|
A |
|
|
A |
|
|
A C++ |
|
|
A |
|
|
A character string ( |
|
|
An object (whether statically typed or typed |
|
|
A class object ( |
|
|
A method selector ( |
|
[array type] |
An array |
|
{name=type...} |
A structure |
|
(name=type...) |
A union |
|
|
A bit field of num bits |
|
|
A pointer to type |
|
|
An unknown type (among other things, this code is used for function pointers) |
Important: Objective-C does not support the long double type. @encode(long double) returns d, which is the same encoding as for double.
The type code for an array is enclosed within square brackets; the number of elements in the array is specified immediately after the open bracket, before the array type. For example, an array of 12 pointers to floats would be encoded as:
[12^f] |
Structures are specified within braces, and unions within parentheses. The structure tag is listed first, followed by an equal sign and the codes for the fields of the structure listed in sequence. For example, the structure
typedef struct example {
|
id anObject; |
char *aString; |
int anInt; |
} Example; |
would be encoded like this:
{example=@*i}
|
The same encoding results whether the defined type name (Example) or the structure tag (example) is passed to @encode(). The encoding for a structure pointer carries the same amount of information about the structure’s fields:
^{example=@*i}
|
However, another level of indirection removes the internal type specification:
^^{example}
|
Objects are treated like structures. For example, passing the NSObject class name to @encode() yields this encoding:
{NSObject=#}
|
The NSObject class declares just one instance variable, isa, of type Class.
Note that although the @encode() directive doesn’t return them, the runtime system uses the additional encodings listed in Table 6-2 for type qualifiers when they’re used to declare methods in a protocol.
Type Encodings的更多相关文章
- Type Encoding
[Type Encodings] The compiler encodes the return and argument types for each method in a character s ...
- 【原】FMDB源码阅读(二)
[原]FMDB源码阅读(二) 本文转载请注明出处 -- polobymulberry-博客园 1. 前言 上一篇只是简单地过了一下FMDB一个简单例子的基本流程,并没有涉及到FMDB的所有方方面面,比 ...
- YYModel 源码解读(二)之YYClassInfo.h (1)
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_END 为了兼容Swift 中的 ? 和 ! oc 在6.3引入了两个新的类型注释:__nullable和__non ...
- iOS - 消息转发处理
详细运行时基础 NSInvocation介绍 NSHipster-Swizzling Objective-C Method相关方法分析 Type Encodings Objc是OOP,所以有多态. 当 ...
- runtime运行时
/** * Describes the instance variables declared by a class. * * @param cls The class to inspect. * @ ...
- Objective C运行时(runtime)
#import <objc/runtime.h> void setBeingRemoved(id __self, SEL _cmd) { NSLog(@"------------ ...
- iOS开发——高级篇——Objective-C特性:Runtime
Objective-C是基于C语言加入了面向对象特性和消息转发机制的动态语言,这意味着它不仅需要一个编译器,还需要Runtime系统来动态创建类和对象,进行消息发送和转发.下面通过分析Apple开源的 ...
- 利用RunTime解决由NSTimer导致的内存泄漏
NSTimer使用场景 用NSTimer来实现每隔一定时间执行制定的任务,例如最常见的广告轮播图,使用NSTimer实现这个功能很简单代码如下 NSTimer *_timer; _timer = [N ...
- iOS开发——语法篇OC篇&高级语法精讲二
Objective高级语法精讲二 Objective-C是基于C语言加入了面向对象特性和消息转发机制的动态语言,这意味着它不仅需要一个编译器,还需要Runtime系统来动态创建类和对象,进行消息发送和 ...
随机推荐
- python(二)面向对象知识点
模块 别名 import my_module as xxx(别名) 先导入内置模块 再导入第三方模块 再导入自定义模块 from my_module(导入的文件) import *(变量) __all ...
- centos中更新glibc库文件到2.17
1 确保安装过gcc yum install gcc 2 获取glibc相关版本 wget http://ftp.gnu.org/pub/gnu/glibc/glibc-2.17.tar.xz 3 解 ...
- MySQL常见的应用异常记录
>>Error Code: 1045. Access denied for user 'test'@'%' (using password: YES) 使用MySQL的select * i ...
- NPOI导出 The maximum column width for an individual cell is 255 characters
增加如下代码 ) { arrColWidth[column.Ordinal] = ; } //设置列宽 sheet.SetColumnWidth(column.Ordinal, (arrColWidt ...
- HTTP协议随笔
代理 代理就是处在客户端和服务端之间的服务器.客户端例如浏览器发送GET请求时,代理服务器接收该请求,并转发该请求至服务所在的服务器.服务器回复的数据和资源在第一时间经过代理服务器,才能回传到浏览器, ...
- (原创)对比组态软件,使用C#开发的服务器和客户端软件的优势
在当前经济形势和市场环境下,中小企业面对萧条的消费市场,恶化的外部贸易环境,刚性支出高成本人工和生产要素,通货膨胀,隐性的腐化支出等各种因素的作用导致企业生存艰难,企业需要在各方面削减支出,拓展市场寻 ...
- C:\Program不是内部或外部命令,也不是可运行的程序或批处理文件。
问题描述:C:\Program不是内部或外部命令,也不是可运行的程序或批处理文件. 解决办法:C:\"Program Files"\具体文件目录. 具体场景:在cmd或者批处理文件 ...
- python基础08--迭代器,生成器
1.1 迭代器 1.可迭代对象:str,list,tuple,set,dict, 迭代器:f(文件),range() 可迭代对象和迭代器都可以for循环 可迭代对象不会计数, 迭代器会计数,上面操作到 ...
- 使用 sql server 默认跟踪分析执行的 SQL 语句
如果没有启用 SQL SERVER 的跟踪器来跟踪 SQL SERVER 的 SQL 执行情况,又想查最近的 SQL 执行情况,网上一般说是使用 LogExprorer 这个工具,网上找了这个工具很久 ...
- JavaScript 之 事件(详解)
一.注册事件的三种方式 1.直接事件方式 语法格式: 变量名.on事件名 = function() {} 注意:这种方式无法给同一对象的同一事件注册多个事件处理函数 2.addEventListene ...