Quote:
Originally Posted by Esko2300
Thanks for both your explanation's im starting to understand why i would exactly use NSInvocation in my programs. Another question though how would i go about using the [invocation setReturnType:&r] and [invocation getReturnType:&t]?
|
You should not need to use setReturnType, because the two statements
instanceMethodSignatureForSelector
and
invocationWithMethodSignature:
should get everything they need to know about the method (number and types of parameters, type of method return type, if any). You pass that method signature to the method invocationWithMethodSignature to create your invocation object.
As to how to get the return type: Why do you need it? It seems to me that if you're firing off a method using a timer, the return value will simply be ignored. You're not calling the method in the normal way, where you can evaluate the result after the method call and decide what to do next. The timer will fire off the method that's described in the invocation, and then queue up another call (if the timer is a repeating timer.)
I am no expert on invocations, mind. The only time I could think of that you would use the result of a method you invoked with an NSInvocation is if you invoked the method synchronously and waited around for the result to be returned to you.
I just looked at your growRectangle method. It looks to me like you are missing the point of NSInvocation objects completely.
An NSInvocation lets you turn a method call and it's parameters into an object. You can then use the invocation object to invoke that method at a later time.
The invocation object is used to call a method, but in the called method, everything seems normal. You're not aware that there was an NSInvocation object involved. Your method got called with it's normal parameters, and returns whatever value it normally returns. You don't have access to the invocation object inside your called method, and have no reason to want to.
Thus, your growRectangle method should not make any references to an invocation object. You won't have a pointer to it, and should not have a pointer to it. It may even be deallocated by the time your growRectangle method gets called.