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系统来动态创建类和对象,进行消息发送和 ...
随机推荐
- golang开始篇
一 First Golang 1.1 需求 第一个程序hello.go,可以输出"hello golang" 1.2 开发步骤 开发这个程序时,我们的目录结构怎么处理(让自己或 ...
- scala 函数式编程之集合操作
Scala的集合体系结构 // Scala中的集合体系主要包括:Iterable.Seq.Set.Map.其中Iterable是所有集合trait的根trai.这个结构与Java的集合体系非常相似. ...
- Linux中常用命令pipe
大多数linux命令处理数据后都会输出到标准输出,但是如果数据要经过系列列的步骤处理后,才是需要的数据个数,这种需求就需要管道来帮助完成. 管道命令使用"|"作为界定符,将界定符前 ...
- http://www.cnblogs.com/xdp-gacl/p/4200090.html
孤傲苍狼 只为成功找方法,不为失败找借口! JavaWeb学习总结(五十)——文件上传和下载 在Web应用系统开发中,文件上传和下载功能是非常常用的功能,今天来讲一下JavaWeb中的文件上传和下载功 ...
- dotnet core 之 CORS使用示例
这里列举几个经过验证的可用的CORS使用示例, 方便在需要的时候可以直接使用 示例1 #region snippet2 public void ConfigureServices(IServiceCo ...
- 像Java一样管理对象:T&形式仅仅用在参数传递
类的对象为了关联/包含一个T类型的instance,若成员变量包括T*/ T&, 这种设计叫做“aggregation”(聚合):而若采用T 形式,则称为"composition&q ...
- 【MySQL】MySQL高可用架构之MHA
一.关于MHA MHA(Master HA)是一款开源的MySQL的高可用程序,它为MySQL主从复制架构提供了automating master failover 功能.MHA在监控到master节 ...
- github上好用的非代码工具
1. github上好用的非代码工具 1.1. 面试题地址 地址 1.2. 书籍 这里 1.3. 百度网盘不限速下载器 这里
- 《高性能javascript》随笔
1.css文件在head标签中引入,保证在渲染结构的时候进行样式渲染2.Js文件放在body的底部,确保在渲染dom树的时候不会出现js阻塞3.函数内的变量是访问速度最快的,全局变量的访问速度是最慢的 ...
- Android-----ListView组件使用(实现点击选择)
在Android中的ListView选单组件,是以下列表方式来列出选项,供用户选择. ListView组件属性设置: 创建spinner组件时,只需要设置一项entries属性即可使用.此属性是设置要 ...