Here is the object, and have following attribute:
NSString attri1;
NSString attri2;
NSString attri3;
NSString attri4;
If I want to list the
If you want to dynamically access a property of an object, that can be done with Key Value Coding.
If the class is KVC-compliant, as most NS classes are, you can use valueForKey:
or valueForKeyPath:
to access a property with a string:
for(int i = 0; i < [array count]; i++) {
NSLog([[aObj valueForKey:[NSString stringWithFormat:@"attrib%d", i]]);
}
The feature you're looking for is generally called "variable variables." Objective-C does not have this feature. Actually, most languages don't.
The good news is that you don't actually need this feature. Four variables named the same thing with a number at the end is basically equivalent to an array, only with the structure being implicit rather than explicit. Just make attri
an array and then you can ask it for a numbered item.