美文网首页
[搬运]Runtime个人学习

[搬运]Runtime个人学习

作者: 月咏蝴蝶 | 来源:发表于2016-01-12 18:00 被阅读44次

iOS runtime学习笔记
Objective-C Runtime
Runtime详细讲解介绍在上面两个博客已有详细讲解

  1. runtime中的消息
    ①message(消息)
    message的具体定义很难说,因为并没有真正的代码描述,简单的讲message 是一种抽象,包括了函数名+参数列表,他并没有实际的实体存在。
    ②method(方法)
    method是真正的存在的代码。如:- (int)meaning { return 42; }
    ③selector(方法选择器)
    selector 通过SEL类型存在,描述一个特定的method 或者说 message。在实际编程中,可以通过selector进行检索方法等操作。

  2. 系统在编译的时候,你定义的方法比如:
    -(int)doComputeWithNum:(int)aNum
    会编译成:
    int aClass_doComputeWithNum(aClass *self,SEL _cmd,int aNum)

  3. _cmd关键字

- (void)message  
{  
    self.name = @"James";//通过self关键字给当前对象的属性赋值  
    SEL currentSel = _cmd;//通过_cmd关键字取到当前函数对应的SEL  
    NSLog(@"currentSel is :%s",(char *)currentSel);  
}

打印结果:

ObjcRunTime[693:403] currentSel is :message

相关文章

网友评论

      本文标题:[搬运]Runtime个人学习

      本文链接:https://www.haomeiwen.com/subject/cokckttx.html