Created
February 23, 2015 02:09
-
-
Save armadsen/26f1feca57eaae00821c to your computer and use it in GitHub Desktop.
Person.m for DevMountain Lesson 13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For .h: | |
@interface Person : NSObject | |
@property (nonatomic, strong) NSString *imageName; | |
@property (nonatomic, strong) NSString *name; | |
@property (nonatomic, strong) NSString *phoneNumber; | |
@property (nonatomic, strong) NSString *job; | |
- (id)initWithDictionary:(NSDictionary *)dictionary; | |
- (NSDictionary *)personDictionary; | |
@end | |
// For Person.m: | |
static NSString * const imageNameKey = @"imageName"; | |
static NSString * const nameKey = @"name"; | |
static NSString * const phoneNumberKey = @"phoneNumber"; | |
static NSString * const jobKey = @"job"; | |
@implementation Person | |
- (id)initWithDictionary:(NSDictionary *)dictionary { | |
self = [super init]; | |
if (self) { | |
self.imageName = dictionary[imageNameKey]; | |
self.name = dictionary[nameKey]; | |
self.phoneNumber = dictionary[phoneNumberKey]; | |
self.job = dictionary[jobKey]; | |
} | |
return self; | |
} | |
- (NSDictionary *)personDictionary { | |
NSMutableDictionary *entryDictionary = [NSMutableDictionary new]; | |
if (self.name) { | |
[entryDictionary setObject:self.name forKey:nameKey]; | |
} | |
if (self.imageName) { | |
[entryDictionary setObject:self.imageName forKey:imageNameKey]; | |
} | |
if (self.phoneNumber) { | |
[entryDictionary setObject:self.phoneNumber forKey:phoneNumberKey]; | |
} | |
if (self.job) { | |
[entryDictionary setObject:self.job forKey:jobKey]; | |
} | |
return entryDictionary; | |
} | |
- (NSString *)description { | |
return self.name; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment