iOS NSTimer scheduledTimerWithT
第一步:配置NSInvocation
- (id)performSelector:(SEL)aSelector withArgument:(id)anArgument{
if (aSelector == nil) return nil;
NSMethodSignature *signature = [[self class] instanceMethodSignatureForSelector:aSelector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
invocation.target =self;
invocation.selector = aSelector;
//NSInvocation 有两个隐藏参数,所以anArgument
if ([anArgument isKindOfClass:[NSArray class]]) {
NSInteger count = MIN(signature.numberOfArguments-2, [(NSArray *)anArgument count]);
for (int i = 0; i< count; i++) {
const char*type = [signature getArgumentTypeAtIndex:i +2];
//需要做参数类型判断然后解析成对应类型,这里默认所有参数都是OC对象
if (strcmp(type, "@") == 0) {
id argument = anArgument[i];
[invocation setArgument:&argument atIndex:2+i];
}
}
}
[invocation invoke];
return invocation;
}
####如果您有什么疑问或者书写歧义,非常感激您能留言~