Adds name to Monster detail view.
Adds json initializers for Monster.
This commit is contained in:
@@ -64,7 +64,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
+(int)abilityModifierForScore: (int)score;
|
||||
+(int)hitDieForSize: (NSString*)size;
|
||||
|
||||
-(id)initWithJSON:(NSString*)jsonData;
|
||||
-(id)initWithJSONString:(NSString*)jsonString;
|
||||
-(id)initWithJSONData:(NSData*)jsonData;
|
||||
-(NSString*)meta;
|
||||
-(int)abilityScoreForAbilityScoreName: (NSString*)abilityScoreName;
|
||||
-(int)abilityModifierForAbilityScoreName: (NSString*)abilityScoreName;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -26,8 +26,7 @@
|
||||
monster = [[Monster alloc] init];
|
||||
monster.name = @"Pixie";
|
||||
[_monsters addObject:monster];
|
||||
monster = [[Monster alloc] init];
|
||||
monster.name = @"Acolyte";
|
||||
monster = [[Monster alloc] initWithJSONString:@"{\"name\":\"Acolyte\"}"];
|
||||
[_monsters addObject:monster];
|
||||
|
||||
// Do any additional setup after loading the view.
|
||||
|
||||
Reference in New Issue
Block a user