struct objc_method {

SEL _Nonnull method_name                                 OBJC2_UNAVAILABLE;

char * _Nullable method_types                            OBJC2_UNAVAILABLE;

IMP _Nonnull method_imp                                  OBJC2_UNAVAILABLE;

}

@encode:

将数据类型编码成char*(字符串)形式

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/ObjCRuntimeGuide.pdf

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.

method_getTypeEncoding

使用@encode将消息编码成字符串形式。

编码的格式按照

id objc_msgSend(id self, SEL op, ...)

参量的顺序进行布局。

-(void)log:(SEL)sel

{

Method xxx = class_getInstanceMethod(self.class, sel);

char *ret = method_getTypeEncoding(xxx);

NSLog(@"sel:%s, %s", sel, ret);

}

举例:

-(void)hello

v16@0:8

-(id)hello:(id)x

@24@0:8@16

-(void)hello:(id)x :(id)e

v32@0:8@16@24

解读:

按照文档上的说明,和objc_msgSend的参量顺序

A void v

A method selector (SEL)  :

An object (whether statically typed or typed id) @

进行拆解解读

v16(返回类型为空) @0(receiver id类型) :8(SEL标示)

v32(返回类型为空) @0(receiver id类型) :8(SEL标示)@16(参量 id类型)@24(参量 id类型)

objc_msgSend method_getTypeEncoding 与 @encode的更多相关文章

  1. runtime - 消息发送(objc_msgSend)

    http://www.jianshu.com/p/95c8cb186673 在OC中,我们对方法的调用都会被转换成内部的消息发送执行对objc_msgSend方法的调用,掌握好消息发送,可以让我们在编 ...

  2. 防御XSS攻击-encode用户输入内容的重要性

    一.开场先科普下XSS 跨站脚本攻击(Cross Site Scripting),为不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆,故将跨站脚本攻击缩写为XSS.恶 ...

  3. HttpPost过程中使用的URLEncoder.encode(something, encode)

    URLEncoder.encode("刘美美", "utf-8").toString()       =     %E5%88%98%E7%BE%8E%E7%B ...

  4. [LeetCode] Encode String with Shortest Length 最短长度编码字符串

    Given a non-empty string, encode the string such that its encoded length is the shortest. The encodi ...

  5. [LeetCode] Encode and Decode Strings 加码解码字符串

    Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...

  6. UnicodeEncodeError: 'ascii' codec can't encode characters in position 820-823: ordinal not in range(128)

    真是奇怪了,在itermi里 print(data) 就能直接运行,而在sublime里,就非得写成这样 print(data.encode('utf-8'))

  7. javascript处理HTML的Encode(转码)和Decode(解码)总结

    HTML的Encode(转码)和解码(Decode)在平时的开发中也是经常要处理的,在这里总结了使用javascript处理HTML的Encode(转码)和解码(Decode)的常用方式 一.用浏览器 ...

  8. URLEncoder.encode 和 URLDecoder.decode 处理url的特殊参数

    在使用 url 的 queryString 传递参数时,因为参数的值,被DES加密了,而加密得到的是 Base64的编码字符串,类似于: za4T8MHB/6mhmYgXB7IntyyOUL7Cl++ ...

  9. Python3的decode()与encode()

    python3的decode()与encode() Tags: Python Python3 对于从python2.7过来的人,对python3的感受就是python3对文本以及二进制数据做了比较清晰 ...

随机推荐

  1. KB,MB,GB,TB,PB,EB,ZB,YB,BB

    1 Bit = Binary Digit 8 Bits = 1 Byte 1024 Bytes = 1 Kilobyte 1024 Kilobytes = 1 Megabyte 1024 Megaby ...

  2. C# Convert.ChangeType()

    Convert.ChangeType() 将未知类型转换为已知类型 ; object result = Convert.ChangeType(content, typeof(int)); 其他常用的转 ...

  3. SpringBoot扩展点之二:ApplicationRunner和CommandLineRunner的扩展

    CommandLineRunner并不是Spring框架原有的概念,它属于SpringBoot应用特定的回调扩展接口: public interface CommandLineRunner { /** ...

  4. Flutter 宽高比(比率)控件 AspectRatio

    const AspectRatio({ Key key, @required this.aspectRatio, Widget child,}) void main() {  runApp(    n ...

  5. Nginx入门教程(转)

    原文:https://www.cnblogs.com/qdhxhz/p/8910174.html nginx入门教程 一.概述    什么是nginx?   Nginx (engine x) 是一款轻 ...

  6. Django中使用CORS实现跨域请求(转)

    原文:https://blog.csdn.net/zizle_lin/article/details/81381322 跨域请求: ​    请求url包含协议.网址.端口,任何一种不同都是跨域请求. ...

  7. Celery在Django中的使用介绍

    Celery在Django中的使用介绍 Celery简介 celery是一个简单.灵活且可靠的,处理大量消息的分布式系统,并且提供维护这样一个系统的必须工具. 它是一个专注于实时处理的任务队列,同时也 ...

  8. poj 2102 A计划

    可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老.年迈的国王正是心急如焚,告招天下 ...

  9. ASP.NET Core中使用Cache缓存

    ASP.NET Core中使用Cache缓存 缓存介绍: 通过减少生成内容所需的工作,缓存可以显著提高应用的性能和可伸缩性. 缓存对不经常更改的数据效果最佳. 缓存生成的数据副本的返回速度可以比从原始 ...

  10. Redux 中间件和异步操作

    回顾一下Redux的数据流转,用户点击按钮发送了一个action,  reducer 就根据action 和以前的state 计算出了新的state, store.subscribe 方法的回调函数中 ...