0

Possible Duplicate:
Objective C Introspection/Reflection

I am looking for the way to get the object's members type name in sequence declared in the object header.

such as, if I get an object like this

@interface Person : NSObject {
  int age;
  NSString *name;
  PersonDetail *detail;
}

When I get the data like {28,@"Jack",{@"basketball",@"Male",@"Master Degree"}} in array. I would need the type of members to fill the data in.

It's like in java where there is a function like getField() to get the members in order.

So is there any methods I can use?

Thank.

Community
  • 1
  • 1
David T.
  • 90
  • 1
  • 6

2 Answers2

1

Have a look at the Objective-C Runtime Reference. It includes functions for doing things like getting a class's ivar list (class_copyIvarList()), or get an objects actual ivars (object_getIndexedIvars()) and things like that. It should be able to do something like what you want.

user1118321
  • 25,567
  • 4
  • 55
  • 86
0

You can check the type for above object as follow:

   if( [person isKindOfClass:[Person class]])
    {
       //add your logic here
    }
V-Xtreme
  • 7,230
  • 9
  • 39
  • 79