Mac best look up practice?

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
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
1
Dallas, TX
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
 

Detrius

macrumors 68000
Sep 10, 2008
1,621
19
Asheville, NC
...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?
 

Similar threads

  • Cromulent
7
Replies
7
Views
660
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.