I agree with @TomPace's post, for this small number I would do a simple if/else.
However, there may be times you do need to loop through a list of fields.
It's a bad idea to blindly pull the values into an array as you could be trying inserting nil
values into the array. In this case, it would be better to place the field names into a key array as strings and loop through the list using valueForKey:
to access the values. I would possibly store the keys
list somewhere else where it can be used again.
Person *p = ...
NSMutableString *s = [[NSMutableString alloc] init];
NSArray *keys = @[@"firstName", @"lastName", @"phoneNumber", @"adress", @"city"];
for (NSString *key in keys)
{
NSString *value = [p valueForKey:key];
if ([value length] > 0) {
[s appendFormat:@"%@\n", value];
}
}