Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gonche1124

macrumors newbie
Original poster
Aug 6, 2009
27
0
I need to implement a method that returns a symbol from a table, array, NSdictionary, etc, depending on what you pass as an argument, what is the best way to implement this?

Thanks in advanced

Andres
 
If all possible types are objects, accept an id, then ask isKindOfClass for the various types you can handle, and act accordingly when you get a hit.

-Lee
 
...or, you could take advantage of C and overload the function. It would be a little more efficient since the decision would be made at compile time instead of run time.

Of course, since Objective-C is weakly typed, it's possible you won't know the type at compile time. If you are throwing around "id" already, this would be impractical.


I would like to point out, though, that the parameters required to pull information from an NSDictionary are quite different from that required to pull information from an array. Therefore, I question the feasibility of a method whose purpose is to mask this process. Why not just use the native lookup methods?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.