Here is an example of how the properties of a javascript object can be enumerated through. I noticed that the loop construct used was a for...in
loop. Objective-C also has a for...in
loop, so is the same behavior possible in Objective-C?
@interface Bar : NSObject
@property (nonatomic) NSString * stringA;
@property (nonatomic) NSString * stringB;
@property (nonatomic) NSString * stringC;
@end
int main(int argc, const char *argv[]) {
Bar obj = [[Bar alloc] init];
obj.stringA = @"1";
obj.stringB = @"2";
obj.stringC = @"3";
for (NSString *property in obj) {
NSLog(@"%@", property);
}
}
Is this possible with Objective-C? If not, is there an alternative that would mimmic this behavior of iterating through an objects properties?