1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

getVariableType?

Discussion in 'Mac Programming' started by liptonlover, Sep 11, 2008.

  1. macrumors 6502a

    #1
    1. Will (id *)aValue accept any type of data, including C variables?

    2. I need to find out what kind of variable/data that id is... how do I do that?

    Nate
     
  2. macrumors 68040

    lee1210

    #2
    I am 99% sure id cannot take a primitive, you'd have to wrap it in an NSNumber. Someone that's a little more familiar may want to chime in if this is incorrect, but id in my mind has to allow for type introspection, and primitives don't carry that sort of information.

    Check out:
    http://developer.apple.com/document...//apple_ref/occ/intfm/NSObject/isKindOfClass:
    http://developer.apple.com/document...apple_ref/occ/intfm/NSObject/isMemberOfClass:
    and
    http://developer.apple.com/document...ect.html#//apple_ref/occ/intfm/NSObject/class

    They describe methods that can be called on any NSObject to get its Class or see if it is an object of a particular type. It's not that this is particularly dangerous at all, but runtime introspection (or reflection in some other languages) does require care.

    -Lee

    P.S. Sometimes its just a matter of knowing what to call things. In this case, it's type/runtime introspection. The wikipedia article is actually pretty good on this topic:
    http://en.wikipedia.org/wiki/Introspection_(computer_science)
     

Share This Page