मैं कैसे (या मैं भी एक एनएसआईएनवोकेशन ऑब्जेक्ट को एक शून्य तर्क पास कर सकता हूं?एनएसआईएनवोकेशन शून्य तर्क
मैं यह करने की कोशिश की:
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
धन्यवाद किसी भी मदद के लिए अग्रिम में!
आप सही हैं। समस्या को शून्य मूल्यों के साथ तर्क सेट करने/सेट करने के साथ कुछ लेना देना नहीं है। मेरे गैर-शून्य तर्कों में से एक एक डबल आदिम सरणी है और मैं इसे आमंत्रण ऑब्जेक्ट में पास करने से पहले इसे डबल पॉइंटर में डालना भूल गया था। –