Store the first and last names as NSString
properties and convert from char *
as soon as possible.
@interface MyObject : NSObject
@property (nonatomic) NSString *firstName;
@property (nonatomic) NSString *lastName;
@property (nonatomic, readonly) NSString *fullName;
@end
@implementation MyObject
...
- (NSString *)fullName {
return [NSString stringWithFormat:@"%@ %@", self.firstName, self.lastName];
}
@end
// Using code:
char firstName[] = "Mickey";
char lastName[] = "Mouse";
MyObject *o = [MyObject new];
// Old way:
//o.firstName = [NSString stringWithUTF8String:firstName];
//o.lastName = [NSString stringWithUTF8String:lastName];
// New way (thanks to @MartinR for reminding me):
o.firstName = @(firstName);
o.lastName = @(lastName);
NSLog(@"Full name: %@", o.fullName);