それらを直接入れることができないことはわかっていますが、NSNumber
たとえば、に変換する必要があります。それらをNSNumber
s に変換してから、辞書に入れています。入力しているキーをすぐにログに記録すると、それらは空白です。
次に例を示します。
- (NSDictionary*) dictionaryFromWrestler
{
/*
* Used ot create a dictionary from the instance of the wrestler
* Can be used to send and receive wrestlers through notification center
*/
NSDictionary* dictionary;
NSNumber* _score = [NSNumber numberWithInt:score];
dictionary = [NSDictionary dictionaryWithObjectsAndKeys:firstName, @"firstName", lastName, @"lastName", fullName, @"fullName", shortName, @"shortName", team, @"team", seed, @"seed", actualWeight, @"actualWeight", dob, @"dob", club, @"club", hometown, @"hometown", state, @"state", grade, @"grade", extraField, @"extraField", phone, @"phone", address, @"address", zip, @"zip", record, @"record", gradeAbbr, @"gradeAbbr", twid, @"twid", teamId, @"teamId", position, @"position", _score, @"score", [NSNumber numberWithInt:teamScore], @"teamScore", [NSNumber numberWithInt:period1Score], @"period1Score", [NSNumber numberWithInt:period2Score], "@period2Score", [NSNumber numberWithInt:periods], @"periods", [NSNumber numberWithBool:hasRidingTime], @"hasRidingTime", nil];
NSLog(@"dictionaryFromWrestler Score: %@", lastName);
NSLog(@"dictionaryFromWrestler Score: %i", score);
NSLog(@"dictionaryFromWrestler Score: %@", _score);
NSLog(@"dictionaryFromWrestler Score: %d", [[dictionary objectForKey:@"score"] intValue]);
NSLog(@"dictionaryFromWrestler Score: %@", [dictionary valueForKey:@"score"]);
NSLog(@"dictionaryFromWrestler Score: %@", [dictionary valueForKey:@"lastName"]);
return dictionary;
}
私のログは次のようになります。
2012-05-18 17:46:53.117 Wrestling Tools[31509:403] dictionaryFromWrestler Score: Brown
2012-05-18 17:46:53.117 Wrestling Tools[31509:403] dictionaryFromWrestler Score: 2
2012-05-18 17:46:53.117 Wrestling Tools[31509:403] dictionaryFromWrestler Score: 2
2012-05-18 17:46:53.117 Wrestling Tools[31509:403] dictionaryFromWrestler Score: (null)
2012-05-18 17:46:53.117 Wrestling Tools[31509:403] dictionaryFromWrestler Score: (null)
2012-05-18 17:46:53.117 Wrestling Tools[31509:403] dictionaryFromWrestler Score: Brown
ご覧のとおり、プリミティブは失敗しますが、オブジェクトは機能します。一体何?