关于优化Objective C程序的另一个问题启发了以下内容:当theMethod有两个(或更多)整数输入时,是否有人使用SEL和IMP的简短示例?
sho*_*sti 50
这是获取当前IMP 的一个很好的教程(概述了IMP).IMP和SEL的一个非常基本的例子是:
- (void)methodWithInt:(int)firstInt andInt:(int)secondInt { NSLog(@"%d", firstInt + secondInt); }
SEL theSelector = @selector(methodWithInt:andInt:);
IMP theImplementation = [self methodForSelector:theSelector]; 
//note that if the method doesn't return void, you have to explicitly typecast the IMP, e.g. int(* foo)(id, SEL, int, int) = ...
然后您可以像这样调用IMP:
theImplementation(self, theSelector, 3, 5);
除非你正在做严肃的伏都教,否则通常没有理由需要IMPs - 你有什么特别的想做吗?
| 归档时间: | 
 | 
| 查看次数: | 28126 次 | 
| 最近记录: |