runtime-class_addMethod\objc_msgSend\NSInvocation
来源:互联网 发布:.love域名 编辑:程序博客网 时间:2024/05/16 10:47
#import <objc/runtime.h>
#import <objc/message.h>
TestClass *instance = [[TestClass alloc]init]; //给testclass添加一个fun class_addMethod([TestClass class],@selector(ocMethodA::), (IMP)cfunctionA,"@@:@@"); if ([instance respondsToSelector:@selector(ocMethodA::)]) { NSLog(@"Yes, instance respondsToSelector:@selector(ocMethodA::)"); NSString *myString = @"我是一个OC的method,C函数实现"; NSString *myString2 = @"-----我是第二个参数"; //方法1 objc_msgSend(instance, @selector(ocMethodA::),myString,myString2); //方法2 SEL mySelector = @selector(ocMethodA::); NSMethodSignature * sig = [[TestClass class] instanceMethodSignatureForSelector: mySelector]; NSInvocation * myInvocation = [NSInvocation invocationWithMethodSignature: sig]; [myInvocation setTarget: instance];//0 [myInvocation setSelector: mySelector];//1 [myInvocation setArgument: &myString atIndex: 2]; [myInvocation setArgument: &myString2 atIndex: 3]; NSString* result = nil; [myInvocation retainArguments]; [myInvocation invoke]; [myInvocation getReturnValue: &result]; NSLog(@"The NSInvocation invoke string is: %@", result); } else { NSLog(@"Sorry"); }
NSString* cfunctionA(id self, SEL _cmd, NSString *str, NSString *str1) { NSLog(@"%@%@", str,str1); return @"结果返回";//随便返回个值 }
0 0
- runtime-class_addMethod\objc_msgSend\NSInvocation
- runtime objc_msgSend
- runtime-objc_msgSend
- Runtime之objc_msgSend函数
- iOS笔记-runtime objc_msgSend
- runtime objc_msgSend消息发送
- Objective-C Runtime 【objc_msgSend函数】
- iOS用runtime给一个类动态添加方法 ---class_addMethod
- Objective-C Runtime分析(三)-objc_msgSend
- runtime简单理解之消息传递 objc_msgSend
- objc_msgSend
- NSInvocation
- NSInvocation
- NSInvocation
- NSInvocation
- NSInvocation
- NSInvocation
- NSInvocation
- wpf总结
- Python自动单元测试框架
- 回调函数
- 卸载其他进程中的dll模块
- java IO文件操作入门经典例子
- runtime-class_addMethod\objc_msgSend\NSInvocation
- 软件工程师的抉择,看起来很美!
- 【甘道夫】info could only be replicated to 0 nodes, instead of 1
- sql
- Java接口,抽象类,内部类
- java单元测试(使用junit)
- C++第8周(春)项目1 实现复数类中的运算符重载
- 正确使用UDP广播(C++代码)
- OpenGL提示“pixel format with necessary capabilities not found”