Casebash
Casebash

Reputation: 118792

Utility function for NSInvocation

NSInvocation seems to be one of the worst designed functions in Cocoa, so I decided to check if anyone had written a recipe to make using it easier. I found a recipe on Matt Gallagher's blog. Now to be able to do this he used some quite hackish techniques.

  1. Would you recommend using this code or is this technique too likely to lead to a hard to debug error?
  2. If not, what would you recommend instead?

Upvotes: 1

Views: 503

Answers (2)

Matt Gallagher
Matt Gallagher

Reputation: 14968

I have used this NSInvocation approach in a few shipping iPhone products and Mac products. It definitely employs a few strange techniques but it's not a fragile hack by any means: it's rock solid and about as fast as NSInvocation creation is likely to be.

I did briefly have a retain count bug in the code (long since fixed) but it's no harder to debug retain counts here than anywhere else.

Of course, my opinion is completely biased.

Upvotes: 2

Casebash
Casebash

Reputation: 118792

The simplest utility function would have the following interface

+ (id)retainedInvocationWithTarget:(id)target invocationOut:(NSInvocation
**)invocationOut args:NSDictionary;

This would have the disadvantage that nil cannot be passed in for the arguments. I think there should be a better solution

UPDATE: NSNull can be used in dictionaries instead of nil

Upvotes: 0

Related Questions