我知道我不能直接把它们放进去,但我必须把它们转换成一个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
如您所见,原语失败了,但对象工作。有没有搞错?