ARC環境でNSInvocationを使う機会があり、ハマってしまったので、対策をメモしておきます。
要は、[invocation retainArguments]を追加するだけなのですが、
これがないと、
unrecognized selector sent to instance
と実行時エラーになります。
if (target && selector) {
NSMethodSignature *signature = [[target class] instanceMethodSignatureForSelector:selector];
if (signature != nil) {
self.invocation = [NSInvocation invocationWithMethodSignature:signature];
[self.invocation retainArguments]; // <- ここ
[self.invocation setTarget:target];
[self.invocation setSelector:selector];
[self.invocation setArgument:(__bridge_retained void *)self atIndex:2];
}
}