I need to build an NSString that resembles the following:
Name: Craig Buchanan
Phone: 800-555-1212
Email: name@company.com
Where:
- each row (e.g. phone) is included or excluded based on the UISwitch value
- the key part of the line (ie the part to the left of ":") is localized
- part of the value is from a UITextField.
My approach:
NSMutableArray *values = [[NSMutableArray alloc] initWithCapacity:3];
if (self.nameSwitch.isOn)
[values addObject:[NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"Name", @"Name label"), textFieldName.text]];
if (self.telephoneSwitch.isOn)
[values addObject:[NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"Telephone", @"Telephone number label"), textFieldTelephone.text]];
if (self.emailSwitch.isOn)
[values addObject:[NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"Email", @"Email address label"), textFieldEmail.text]];
return [values componentsJoinedByString:@"\r"];
I have a few questions:
- Is this a decent approach (am I objective-c noob)?
- I understand that my array is auto-implemented, but still I am concerned about memory usage. Should I release an auto-release pool? seems a little dangerous.
- . , , UISwitch , . ?
,