iPhone OS: Get a list of methods and variables from anonymous object
- by ChrisOPeterson
I am building my first iPhone/Obj-c app and I have a large amount of data-holding subclasses that I am passing into a cite function. To the cite function these objects are anonymous and I need to find a way to access all the variables of each passed object.
I have been using a pre-built NSArray and Selectors to do this but with more than 30 entries (and growing) it is kind of silly to do manually. There has to be a way to dynamically look up all the variables of an anonymous object.
The obj-c runtime run-time docs mention this problem but from what I can tell this is not available in iPhone OS. If it is then I don't understand the implementation and need some guidance. A similar question was asked before but again I think they were talking about OSX and not iPhone.
Any thoughts?
-(NSString*)cite:(id)source {
NSString *sourceClass = NSStringFromClass([source class]);
// Runs through all the variables in the manually built methodList
for(id method in methodList) {
SEL x = NSSelectorFromString(method);
// further implementation
// Should be something like
NSArray *methodList = [[NSArray alloc] initWithObjects:[source getVariableList]]
for(id method in methodList) {
SEL x = NSSelectorFromString(method);
// Further implementation
}