p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px “Yuanti SC” }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px “Yuanti SC”; color: #0433ff }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px “Yuanti SC”; color: #aa7942 }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px “Yuanti SC”; color: #d12f1b }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px “Yuanti SC”; color: #ff2600; background-color: #ffffff }
p.p6 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px “Yuanti SC”; color: #3e1e81; background-color: #ffffff }
p.p7 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px “Yuanti SC”; color: #ff40ff; background-color: #ffffff }
p.p8 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px “Yuanti SC”; color: #008400 }
p.p9 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px “Yuanti SC”; color: #3e1e81 }
p.p10 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px “Yuanti SC”; min-height: 20.0px }
p.p11 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px “Yuanti SC”; color: #0433ff; background-color: #ffffff }
p.p12 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px “Yuanti SC”; background-color: #ffffff; min-height: 20.0px }
p.p13 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px “Yuanti SC”; color: #3e1e81; background-color: #ffffff; min-height: 20.0px }
p.p14 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #3e1e81; background-color: #ffffff }
p.p15 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #ff40ff; background-color: #ffffff }
p.p16 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #ff2600; background-color: #ffffff }
p.p17 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #008400; background-color: #ffffff }
p.p18 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px “PingFang SC”; color: #008400; background-color: #ffffff }
p.p19 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #000000; background-color: #ffffff }
span.s1 { color: #000000 }
span.s2 { color: #ff2600; background-color: #ffffff }
span.s3 { background-color: #ffffff }
span.s4 { color: #008400; background-color: #ffffff }
span.s5 { color: #78492a; background-color: #ffffff }
span.s6 { color: #008400 }
span.s7 { color: #ff2600 }
span.s8 { color: #0433ff }
span.s9 { color: #3e1e81 }
span.s10 { color: #919191 }
span.s11 { color: #4f8187; background-color: #ffffff }
span.s12 { color: #000000; background-color: #ffffff }
span.s13 { color: #d12f1b; background-color: #ffffff }
span.s14 { font: 14.0px “Yuanti SC” }
span.s15 { color: #4f8187 }
span.s16 { font: 12.0px “PingFang SC”; color: #000000 }
span.s17 { font: 12.0px “PingFang SC” }
span.s18 { color: #ba2da2 }
span.s19 { color: #703daa }
span.s20 { color: #d12f1b }
span.s21 { font: 12.0px Menlo; color: #000000 }
span.s22 { font: 12.0px Menlo }
span.s23 { font: 12.0px “PingFang SC”; color: #d12f1b }

//Person * p = [[Person alloc] init];

//alloc :分配内存空间  init:初始化对象,属性&方法

//苹果不建议我们使用Objc_msgSend , 在build-setting 搜索 msg 打开

//导入 #import <objc/message.h>

// objc_msgSend        消息发送

//  objc_getClass        获取类名

//  sel_registerName  注册方法编号

//OC 转C  OC 中 1.SEL 方法编号

   Person * p = objc_msgSend(objc_getClass(“Person”), sel_registerName(“alloc”));

 

//p = [p init];

    p = objc_msgSend(p, sel_registerName(“init”));

 

//[p eatWith:@”汉堡!!”];

//传参数

 

    objc_msgSend(p, sel_registerName(“eatWith:”),@”汉堡!!”);

//给父类发送消息

 

         HKPerson * p = [[HKPerson alloc] init];

    //objc_super 结构体指针

    //class_getSuperclass 获取父类类型

    //定义hkSuper 结构体

    struct objc_super hkSuper = {p ,class_getSuperclass(objc_getClass(“HKPerson”))};

    //给父类发送消息

    objc_msgSendSuper(&hkSuper, @selector(eatWith:),@”汉堡“);

 

clang编译工具将OC main.m 编译成C++代码

 

$ clang -rewrite-objc main.m 

将OC 转 C++

Person * p = [Person alloc];
p = [p init];
int main(int argc, const char * argv[]) {
    /* @autoreleasepool */ { __AtAutoreleasePool __autoreleasepool; 
        Person * p = ((Person *(*)(id, SEL))(void *)objc_msgSend)((id)objc_getClass("Person"), sel_registerName("alloc"));
        p = ((Person *(*)(id, SEL))(void *)objc_msgSend)((id)p, sel_registerName("init"));
    }
    return 0;
}

 

 

 

 

 

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px “Yuanti SC”; color: #0433ff }

版权声明:本文为StevenHuSir原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/StevenHuSir/p/Runtime_Objc_msgSend.html