https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtHowMessagingWorks.html#//apple_ref/doc/uid/TP40008048-CH104-SW1

When objc_msgSend finds the procedure that implements a method, it calls the procedure and passes it all the arguments in the message. It also passes the procedure two hidden arguments:

  • The receiving object

  • The selector for the method

These arguments give every method implementation explicit information about the two halves of the message expression that invoked it. They’re said to be “hidden” because they aren’t declared in the source code that defines the method. They’re inserted into the implementation when the code is compiled.

Although these arguments aren’t explicitly declared, source code can still refer to them (just as it can refer to the receiving object’s instance variables). A method refers to the receiving object as self, and to its own selector as _cmd. In the example below, _cmd refers to the selector for the strange method and self to the object that receives a strange message.

self & _cmd的更多相关文章

  1. Swift #function 和 _cmd (Objective-C)

    NSStringFromSelector(_cmd); // Objective-C print(__FUNCTION__) // Swift 2 print(#function) // Swift ...

  2. object-c [self class] 和 [self _cmd]

    [self class] 返回当前类名 [self _cmd] 返回当前方法名 self 是类的隐藏的参数,指向当前当前调用方法的类 另一个隐藏参数是_cmd,代表当前类方法的selector

  3. 关于_cmd

    实际上是该方法名(@selector的名称). 比如: - (void)someCategoryMethod { NSString *string = objc_getAssociatedObject ...

  4. 第20月第14天 objc_getAssociatedObject _cmd

    1. - (CustomNavigationControllerDelegate *)customDelegate { return objc_getAssociatedObject(self, _c ...

  5. Runtime 中的 _cmd、 IMP

    IMP IMP-指向实际执行函数体的函数指针 #if !OBJC_OLD_DISPATCH_PROTOTYPES typedef void (*IMP)(void /* id, SEL, ... */ ...

  6. 常用的底层语法(objc_get,class_get,_cmd,objc_msgSend)

    一,关联 objc_get 1)建立关联:objc_setAssociatedObject:该函数需要四个参数:源对象,关键字,关联的对象和一个关联策略:当源对象销毁,关联的对象也会被销毁 源对象: ...

  7. NSStringFromSelector(_cmd)和self

    1._cmd是隐藏的参数,代表当前方法的selector,他和self一样都是每个方法调用时都会传入的参数,动态运行时会提及如何传的这两个参数, 你在方法里加入CCLOG(@\"%@, %@ ...

  8. IMP self _cmd

    The only way to circumvent dynamic binding is to get the address of a method and call it directly as ...

  9. zzw原创_cmd下带jar包运行提示 “错误: 找不到或无法加载主类 ”

    在windows下编译java,由于是临时测试一下文件,不想改classpath,就在命令行中用 -cp 或classpath引入jar包,用javac编译成功,便使用java带-cp 或classp ...

随机推荐

  1. memcpy() 实现循环缓冲区数据的读写

    使用memcpy()函数做循环缓冲区的读写 首先对mencpy函数做个简单的介绍 下面是 memcpy() 函数的声明 void *memcpy(void *str1, const void *str ...

  2. vue mint-ui 框架下拉刷新上拉加载组件的使用

    安装 npm i mint-ui -S 然后在main.js中引入 import MintUI from 'mint-ui' import 'mint-ui/lib/style.css' Vue.us ...

  3. LOJ2257 SNOI2017 遗失的答案 容斥、高维前缀和

    传送门 数字最小公倍数为\(L\)的充分条件是所有数都是\(L\)的约数,而\(10^8\)内最多约数的数的约数也只有\(768\)个.所以我们先暴力找到所有满足是\(L\)的约数.\(G\)的倍数的 ...

  4. drools -规则语法

    文章结构 1. 基础api 2. FACT对象 3. 规则 4. 函数 1. 基础api 在 Drools 当中,规则的编译与运行要通过Drools 提供的各种API 来实现,这些API 总体来讲可以 ...

  5. linux或者shell进入vi命令

    vi的基本操作 a) 进入vi     在系统提示符号输入vi及文件名称后,就进入vi全屏幕编辑画面: $ vi file  不过有一点要特别注意,就是您进入vi之后,是处于「命令行模式(comman ...

  6. Linux学习笔记之Linux文件系统详解

    0x00 机械硬盘 机械磁盘由磁头(head).磁道(track).柱面(cylinder).扇区(sector)和盘片(platter)组成.其中,磁头悬浮在盘片上,并且每张盘片上下各有一个磁头:每 ...

  7. spark过滤算子+StringIndexer算子出发的一个逻辑bug

    问题描述: 在一段spark机器学习的程序中,同时用到了Filter算子和StringIndexer算子,其中StringIndexer在前,filter在后,并且filter是对stringinde ...

  8. js设置全局变量与读取全局变量

    方法1: 设置: var a = 1; 读取: a window.a window['a'] 方法2: 设置: window.b=2; 读取: b window.b window['b'] 方法3: ...

  9. Java 字符串(一)字符串初始化

    一.String类概述 1.概述 java.lang.String 类代表字符串.Java程序中所有的字符串文字(例如 "abc" )都可以被看作是实现此类的实例.String 是 ...

  10. xenserver增加新硬盘

    1. 查看所有硬盘了的id # ls -l /dev/disk/by-id/ 2. 挂载 # xe sr-create type=lvm content-type=user device-config ...