hi, i am new to NSInvocation, what it means?what is the advantage of it?can any one say cllearly from Beginning?
+1
A:
NSInvocation's a reification of a message send. In other words, it's an object that represents the sending of a message.
Say your class Foo has a method called -[Foo foo], and a method like this:
-(void)doSomething {
NSInvocation *inv = [NSInvocation invocationWithMethodSignature: [self methodSignatureForSelector: @selector(foo)]];
[inv setTarget: self];
[inv invoke];
}
Then saying [self foo] is functionally the same thing as saying [self doSomething].
Why would you want to do this? The CubePuzzle sample app gives one idea. Another might be to schedule a message send to take place in the future, say as triggered by an NSTimer.
Frank Shearar
2010-03-25 14:25:06
i could not run CubsPuzzle, what is the difference between[inv invoke];[self foo];why should i use [inv invoke];
Mikhail Naimy
2010-03-25 14:54:18
In one sense, they're identical. In other sense, they're worlds apart: instead of sending a message to an object instantly you can choose to delay that invocation by using an NSInvocation and an NSTimer. Or you could have, like in CubePuzzle, the choice of which selector to run separated from the invocation of that selector (to improve readability/extensibility).
Frank Shearar
2010-03-25 15:03:47