best look up practice?

Discussion in 'Mac Programming' started by gonche1124, Dec 9, 2009.

  1. gonche1124 macrumors newbie

    Joined:
    Aug 6, 2009
    #1
    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
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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
     
  3. Detrius macrumors 68000

    Joined:
    Sep 10, 2008
    Location:
    Asheville, NC
    #3
    ...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?
     

Share This Page