NSInvocationオブジェクトにnil引数を渡すにはどうすればよいですか(またはできますか)。NSInvocation nil引き数
私はこれを実行しようとしました:
NSMethodSignature* signature = [AClass instanceMethodSignatureForSelector:@selector(aMethod:theOtherArg:)];
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: signature];
[invocation setTarget: aTargetObj];
[invocation setSelector: @selector(aMethod:theOtherArg:)];
/* I've tried both this way */
AnObj* arg1 = nil;
AnotherObj* arg2 = nil;
[invocation setArgument: &arg1 atIndex:2];
[invocation setArgument: &arg2 atIndex:3];
/* and this way */
//[invocation setArgument: nil atIndex:2];
//[invocation setArgument: nil atIndex:3];
NSInvocationOperation* operation = [[NSInvocationOperation alloc] initWithInvocation:invocation];
//opQueue is an NSOperationQueue object
[opQueue addOperation:operation];
最初のアプローチは、このメッセージでクラッシュします:
Thread 0 Crashed:
0 libSystem.B.dylib 0x927c1f10 strlen + 16
1 com.apple.CoreFoundation 0x92dd1654 __NSI3 + 500
2 com.apple.CoreFoundation 0x92dd1994 -[NSInvocation retainArguments] + 132
3 com.apple.Foundation 0x96a50c5e -[NSInvocationOperation initWithInvocation:] + 78
第二のアプローチは、このメッセージでクラッシュします:
Error: Exiting due to caught object *** -[NSInvocation setArgument:atIndex:]: NULL address argument
感謝助けを求めて事前に!
あなたは正しいです。この問題は、nil値で引数を設定する/しないこととは関係ありません。私のnon-nil引数の1つはdoubleプリミティブ配列で、呼び出しオブジェクトに渡す前にdoubleポインタにキャストするのを忘れていました。 –