How to get object type

Discussion in 'iOS Programming' started by diyora, Aug 18, 2008.

  1. diyora macrumors newbie

    Joined:
    Jul 21, 2008
    #1
    Hello,
    I want to know the object type in cocoa.
    Suppose object (id) is consider in which i store string,int,etc..
    But i want to know the type of (id).

    Thank you...
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    id is simply void *. If you meant what is the class of object currently being pointed to you can simply ask it:

    Code:
    id someObject;
    // Do something to point someObject at an object
    NSLog(NSStringFromClass([someObject class])); // You can also ask for className directly
    
     
  3. diyora thread starter macrumors newbie

    Joined:
    Jul 21, 2008
    #3
    Thanks for your kind reply.

    This is ok for NSString and like wise Class type.
    But what aboout NSInteger, NSUInteger, etc. basic types?
    It is not working with NSInteger.
    Any other way?

    Thanks.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    NSInteger etc are not objects and should not be assigned to id pointers. If you do so you run the risk of accessing them as objects. If you insist on storing them in this way there is no way of finding their type later.
     

Share This Page