[消息传递之三]-NSInvocation练习
2016-01-09 08:17
190 查看
- (void)viewDidLoad { [super viewDidLoad]; id m = [[MyInvoc alloc] init]; SEL s = @selector(myLen:); NSMethodSignature* sign = [MyInvoc instanceMethodSignatureForSelector:s]; NSInvocation* n = [NSInvocation invocationWithMethodSignature:sign]; [n setTarget:m]; [n setSelector:s]; NSString* w = @"hello world"; [n setArgument:&w atIndex:2]; [n invoke]; NSInteger r ; [n getReturnValue:&r]; NSLog(@"length is %ld",r); // NSLog(@"name is %@, length is %ld",[m name], [m length]); }
1,nsinvocation能传递多个参数,并且能获取返回值,这两点比performselector;withobject要强大。
2,需要配合方法签名使用,幸好这个获取签名的函数在nsobject里面就有~
3,在哪个线程调用,就用哪个线程执行,貌似没有延迟执行方法,这个与performselector有差别~
相关文章推荐
- 引用的简单用法
- Python学习-使用matplotlib画动态多图
- css3系列教程--animation
- Win10更新补丁KB3122947报错80070643使用命令解决的办法
- 日经春秋 20160109
- 天声人語 20160109 歴史観、憲法観の深い溝
- HTML5的LocalStorage、SessionStorage学习
- 定义文档兼容性,是浏览器兼容各个版本号
- C#如何用delegate实现Javascript的each方法
- Java EE V7.0学习笔记-WebLogic Server 安装与配置
- css系列教程--文本
- Android开发Tips(1)
- JavaScript W3学习笔记
- 理解PPAPI的设计
- Linux-CentOS VNC服务器的安装和配置
- 什么是未来的互联网基础服务?
- springmvc+spring+mybatis制作一个博客(1)
- OSChina 周六乱弹 —— 有人骂你神经病怎么办?
- 判别用户之后启动程序
- Windows下使用virtualenv