Adds name to Monster detail view.

Adds json initializers for Monster.
This commit is contained in:
2020-09-06 17:33:58 -07:00
parent d338d42912
commit 0ff71193d6
4 changed files with 78 additions and 4 deletions

View File

@@ -19,16 +19,31 @@
}
-(id)init {
NSLog(@"TOM_init");
self = [super init];
self.name = @"";
// TODO: Actually initialize the class.
return self;
}
-(id)initWithJSON: (NSString*)jsonData {
-(id)initWithJSONString: (NSString*)jsonString {
NSLog(@"TOM_initWithJSONString");
NSData* jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
return [self initWithJSONData:jsonData];
}
-(id)initWithJSONData: (NSData*)jsonData {
NSLog(@"TOM_initWithJSONData");
self = [super init];
NSDictionary *jsonRoot = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
NSString *name = [jsonRoot objectForKey:@"name"];
NSLog(@"decoded name is |%@|", name);
self.name = name;//[jsonRoot objectForKey:@"name"];
// TODO: Actually initialize the class.
return self;