best look up practice?

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

  1. gonche1124 macrumors newbie

    Aug 6, 2009
    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

  2. lee1210 macrumors 68040


    Jan 10, 2005
    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.

  3. Detrius macrumors 68000

    Sep 10, 2008
    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?

Share This Page