An NSInvocation object contains all the elements of an Objective-C message: a target, a selector, arguments, and the return value. Each of these elements can be set directly, and the return value is set automatically when the NSInvocation object is dispatched.
Questions tagged [nsinvocation]
154 questions
7
votes
2 answers
Does -[NSInvocation retainArguments] copy blocks?
NSInvocation's -retainArguments method is useful for when you don't run the NSInvocation immediately, but do it later; it retains the object arguments so they remain valid during this time.
As we all know, block arguments should be copied instead of…

user102008
- 30,736
- 10
- 83
- 104
7
votes
3 answers
NSInvocation getReturnValue: called inside forwardInvocation: makes the returned object call dealloc:
Here's a standalone test.m file that I'm using to test the behavior.
To compile: clang test.m -o test.app -fobjc-arc -ObjC -framework Foundation. Make sure the Xcode command-line tools are installed.
#import
@protocol…

ryanrhee
- 2,550
- 4
- 23
- 25
6
votes
4 answers
Invoke block iOS
I try to invoke some block, but I run into a EXC_BAD_ACCESS.
-(void) methodA {
self.block = ^ {
[self methodB];
};
}
-(void) webViewDidFinishLoad:(UIWebView *)webView {
[block invoke]; // error here (block is not valid id…

Matrosov Oleksandr
- 25,505
- 44
- 151
- 277
6
votes
3 answers
How to pass an argument to a method called in a NSTimer
I have a timer calling a method but this method takes one paramether:
theTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(timer) userInfo:nil repeats:YES];
should be
theTimer = [NSTimer…

Michele
- 681
- 3
- 16
- 27
6
votes
3 answers
Why creating NSInvocation has to specify selector twice
Here is the example code I saw from Apple's "Timer Programming Topics":
NSMethodSignature *methodSignature = [self
methodSignatureForSelector:@selector(invocationMethod:)];
NSInvocation *invocation =…

Samuel Cai
- 213
- 2
- 9
6
votes
4 answers
which one is better to use from NSInvocation or NSNotificationCentre or Delegate methods
Which one is better to use to flow the data from one class to another in the whole project?
NSInvocation
NSNotificationCentre
delegate methods
or by any other methods i am unaware of ??

Pranjal Bikash Das
- 1,092
- 9
- 27
6
votes
2 answers
iOS - Cannot use 'super' as a reference?
I'm trying to use an NSInvocation to invoke a superclass method from the subclass. The code involved is relatively straightforward, it goes like:
- (NSInvocation*) invocationWithSelector:(SEL)selector {
NSInvocation* call = [[NSInvocation…

aroth
- 54,026
- 20
- 135
- 176
5
votes
3 answers
What's the difference between NSInvocation and block?
when i say block i mean:
^(int a) {return a*a;};
besides, block is only support by iOS4 and above.
What is the difference between these two?

holsety
- 323
- 1
- 2
- 13
5
votes
1 answer
In objective-c , how can an object return a different proxy object when itself is assigned as a delegate it implements
I have an object which implements various protocols (like 10 different ones).
For example
@interface MyClass
@end
@implementation
/// a whole bunch of methods for the…

Avba
- 14,822
- 20
- 92
- 192
5
votes
1 answer
Returning an NSString from an NSInvocation using setReturnValue
When I set the return value of an NSInvocation to be an NSString, the invoker is receiving an NSCFString.
In my case I'm mocking to pull a bundle path from file included by unit tests:
[[[_bundlePartial stub] andDo:^(NSInvocation *invocation) {
…

Ben Flynn
- 18,524
- 20
- 97
- 142
5
votes
2 answers
How does forwardInvocation: get called?
Looking only at the Objective-C runtime library, when a message is sent to an object that doesn't respond to it, the runtime system gives the receiver another chance to handle the message. So, the receiver's forward:: method, if implemented, gets…

LuisABOL
- 2,951
- 4
- 25
- 57
5
votes
2 answers
NSInvocationOperation callback too soon
I know similar questions have been asked a few times, but I'm struggling to get my head around how this particular problem can be solved. So far, everything I've done has been carried out on the main tread. I now find that I need to perform an…

beev
- 1,197
- 2
- 16
- 33
5
votes
1 answer
NSInvocation & NSError - __autoreleasing & memory crasher
In learning about NSInvocations it seems like I've got a gap in my understanding about memory management.
Here is a sample project:
@interface DoNothing : NSObject
@property (nonatomic, strong) NSInvocation *invocation;
@end
@implementation…

edelaney05
- 6,822
- 6
- 41
- 65
4
votes
3 answers
How to create an NSInvocation object using a method that takes a pointer to an object as an argument
I would like to create an NSInvocation object using a method that takes a pointer to an NSError object as an argument. An example of this would be the method -
- (BOOL)writeToFile:(NSString *)path options:(NSDataWritingOptions)mask error:(NSError…

Nat Osten
- 278
- 4
- 11
4
votes
1 answer
Using NSOperationQueue for delayed free of malloc'd void* after returning it
I'm using NSInvocation to get some method returns, and unfortunately I seem to have a leak, but can't figure out how to free the void* I'm allocating, after I've returned it from NSInvocation.
In the following implementation I tried to free it with…

Jack Freeman
- 1,414
- 11
- 18