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系统来动态创建类和对象,进行消息发送和 ...
随机推荐
- WPF 营销管理平台
利用空闲时间计划开发一款开源的营销商城平台,项目写的不够规范,有需要可以看看 项目介绍: 前端使用 WPF,采用MVVM模式 后端数据库采用的sqlite 依靠本地化运行 后期可能会采用WebA ...
- TJOI2018简要题解
Day1T1数学计算 按照时间轴建一棵线段树即可,复杂度为\(O(m \log m)\) #include <bits/stdc++.h> #define N 100005 #define ...
- [Atcoder AGC032C]Three Circuits
题目大意:有一张$n$个点$m$条边的无向连通图,判断是否可以从中分出$3$个环,满足三个环覆盖整张图并且没有重复的边.$n,m\leqslant10^5$ 题解:分类讨论.有度数为奇肯定不行,因为连 ...
- MyBatis系列(二) MyBatis接口绑定与多参数传递
前言 通过上一篇博文的,已经可以做到通过MyBatis连接数据库,现在再来介绍一种方法通过接口绑定SQL语句. 不使用接口绑定的方式 不使用接口绑定的方式,是通过调用SqlSession中的selec ...
- mysql提示The server quit without updating PID file /usr/local/mysql/data/localhost.localdomain.pid
chown -R mysql:mysql /var/lib/mysql 解决方法 :给予权限,执行 “chown -R mysql:mysql /var/lib/mysql” “chmod -R 75 ...
- CentOS 7.0 更改SSH 远程连接 端口号
许多学习过redhat 7的同学们,在使用centos的时候总会遇到一些问题,因为centos在安装时会默认开启一些服务,今天我们就来更改下centos 7.0的SSH端口. 操作步骤: 远程登录到c ...
- EasyUI datagrid-export 将datagrid的数据导出至Excel-解决科学计数法
通过EasyUI datagrid-export.js 将datagrid的数据导出至Excel的时候,如果有类似身份证一样很长的数字,需要在后台返回数据的时候在数字前增加一个 “ ”,将数字转为字符 ...
- JavaWeb第一天--HTML
HTML HTML简介 HTML(Hyper TextMarkupLanguage) 超文本标记语言. 超文本: 超越了文本仅仅展示信息的功能范畴,泛指:图片.有样式的文字.超链接. 标记: 标签. ...
- css, js 项目练习之网页换肤
首先,该练习参考自:https://www.jianshu.com/p/2961d9c317a3 我就直接上代码了(颜色可以自己调). HTML: <nav> <li>< ...
- css 平行四边形
平行四边形 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...