第16月第8天 NSInvocation存储 函数指针 va_arg lldb
2024-08-31 00:08:56
1.NSInvocation存储
-(void)setInvok:(id)target sel:(SEL)sel key:(id)key
{
if(!target) return;
NSMethodSignature *sig=[target methodSignatureForSelector:sel];
NSInvocation *invo=[NSInvocation invocationWithMethodSignature:sig];
[invo setTarget:target];
[invo setSelector:sel]; NSDictionary *dict = [self currentStyleDict];
[dict setValue:invo forKey:key];//以key的形式保存invo
} -(NSInvocation*)selectInvok:(NSString *)key style:(PALiveStyle)style
{
NSDictionary *dict = [self getStyleDict:style];
return [dict valueForKey:key];
}
http://blog.sina.com.cn/s/blog_4beb28f30100qask.html
2.函数指针
//常规写法
switch ( oper ){
case ADD:
result = add( oper1, oper2 );
break;
case SUB:
result = sub( oper1, oper2 );
break;
case MUL:
result = mul( oper1, oper2 );
break;
case DIV:
result = div( oper1, oper2 );
break;
...
}
//使用转移表之后的写法
double add( double, double );
double sub( double, double );
double mul( double, double );
double div( double, double );
...
double (*oper_func[])( double, double ) = {
add, sub, mul, div, ...
};
//下面的语句替换前面整条switch语句
result = oper_func[ oper ]( op1, op2 );
https://segmentfault.com/a/1190000000578532
3.runtime
http://justsee.iteye.com/blog/2163777
4.调用是arg后记得传nil
- (bool)startPlayingStream:(NSString *)streamID inView:(UIView*)view
{
// NSInvocation *invo=[[MessageInvok shareInvok] selectInvok:@"start_playing_stream" style:PALiveStyleNormal];
// if(invo)
// {
//// [data retain];
// [invo setArgument:&streamID atIndex:2]; //设置参数
// [invo setArgument:&view atIndex:3]; //设置参数
// [invo invoke]; //调用
// }
// [self invokeMethod:@"start_playing_stream" style:PALiveStyleNormal,streamID,view];
[self invokeMethod:@"start_playing_stream" style:PALiveStyleNormal arg:streamID,view, nil]; return true;
} - (bool)stopPlayingStream:(NSString *)streamID
{ return true;
} -(NSInvocation *)invokeMethod:(NSString *)method style:(PALiveStyle)style arg:(id)arg, ...
{
NSMutableArray *arrayList = [NSMutableArray array]; id eachItem;
va_list argumentList;
if (arg)
{
[arrayList addObject: arg];
va_start(argumentList, arg);
while((eachItem = va_arg(argumentList, id)))
{
[arrayList addObject: eachItem];
}
va_end(argumentList);
} NSInvocation *invo=[[MessageInvok shareInvok] selectInvok:@"start_playing_stream" style:style];
if(invo)
{
for (NSUInteger i =; i<arrayList.count; i++) {
NSInteger idx = i+;
id data = arrayList[i];
[invo setArgument:&data atIndex:idx];
} [invo invoke]; //调用
} return invo;
}
5.lldb e
e aView.backgroundColor = [UIColor greenColor];
http://yulingtianxia.com/blog/2015/11/13/Summary-of-the-first-month-in-the-internship-of-Tencent/
https://github.com/opensource-apple/objc4/blob/master/runtime/Messengers.subproj/objc-msg-x86_64.s
最新文章
- C++-Qt【5】-QT的QString,char*,QByteArray转化以及中文乱码的问题
- 十大Intellij IDEA快捷键(转)
- spi接口的ds1302时钟芯片控制在lcd1602上显示
- CookieStore之Cookie的获取与保存
- 【leetcode】Regular Expression Matching
- MySQL中的备份和恢复
- linux中如何查看进程对应的cpu使用情况?
- BroadcastReceiver的最简单用法
- 为什么iphone手机比android手机流畅
- JDBC小结
- Eclipse + CDT + YAGARTO + J-Link,STM32开源开发环境搭建与调试
- 使用wininet向FTP服务器发送文件
- Qt多线程(有详细例子)
- 笔记:Hibernate 持久化类标注示例-双向1-N关系映射
- 敏捷冲刺每日报告二(Java-Team)
- boostrap日期时间插件datetimepicker使用过程的一些问题总结
- [Swift]LeetCode257. 二叉树的所有路径 | Binary Tree Paths
- 自动的输入号码的辅助软件在ie浏览器下的尝试
- pygame 笔记-6 碰撞检测
- 使用Chrome开发者工具调试Android端内网页(微信,QQ,UC,App内嵌页等)