iOS Type Encodings
来源:互联网 发布:黑玫瑰籽海藻面膜 淘宝 编辑:程序博客网 时间:2024/05/22 05:28
使用runtime动态给一个对象添加方法的时候我们会发现有个参数不是很理解 :那就是第四个 Type Encodings
class_addMethod([self class],sel, (IMP)eat,"v@:");
添加类方法
class_addMethod([self class],sel, (IMP)eat,"v#:");
后来查文档才知道是方法的 返回值、参数 类型
可如果仅仅这么理解那么就不全面。
通过Clang生成的C++代码查看得知,底层是通过objc_msgSend...函数调用,会默认有两个参数,一个是当前实例对象self 一个是方法_cmd
static void _I_DemoClass_TestFunction(DemoClass * self, SEL _cmd) {
DemoClass * obj = objc_msgSend(objc_msgSend(objc_getClass(
"TestClass"
), sel_registerName(
"alloc"
)), sel_registerName(
"init"
));
}
下面是一张type encodings对应表
Code
Meaning
c
A char
i
An int
s
A short
l
A long
l
is treated as a 32-bit quantity on 64-bit programs.
q
A long long
C
An unsigned char
I
An unsigned int
S
An unsigned short
L
An unsigned long
Q
An unsigned long long
f
A float
d
A double
B
A C++ bool
or a C99 _Bool
v
A void
*
A character string (char *
)
@
An object (whether statically typed or typed id
)
#
A class object (Class
)
:
A method selector (SEL
)
[array type]
An array
{name=type...}
A structure
(name=type...)
A union
b
num
A bit field of num bits
^
type
A pointer to type
?
An unknown type (among other things, this code is used for function pointers)
- iOS Type Encodings
- iOS 类型编码(Type Encodings)
- 关于iOS中的type encodings 和method encodings
- iOS 类型编码 Type Encodings 详解
- Type Encodings
- iOS类型编码Type Encodings与属性类型Property Type
- iOS方法返回值和参数对应的Type Encodings
- Objective-C type encodings
- Type Encodings property_getAttributes
- Type Encodings-runtime
- 类型编码(Type Encodings)
- default mappings from payload type numbers to encodings
- Objective-C 运行时编程指南 之 Type Encodings
- Character Encodings
- IOS keyboard type
- iOS expected a type
- IOS type="search"
- Fonts & Encodings [ILLUSTRATED]
- hadoop中NameNode、DataNode、Secondary、NameNode、JobTracker TaskTracker介绍
- 数据结构之图的存储
- UTF8批量转ANSI
- 标准化和归一化
- Android基础小程序
- iOS Type Encodings
- TFT_LCD
- Caffe学习笔记(三):cifar10_quick_train_test.prototxt配置文件分析
- 方立勋_30天掌握JavaWeb_回顾&复习
- 关于Java乱码(2)
- JSP<c:forEach >标签属性
- Vim基本操作
- 题目1169:比较奇偶数个数
- js将字符串转换成json的三种方式