开发者

How to keep partial scores in NSMutableDictionary

I'm want to store partial scores into a NSMutableDictionary. For each new score I want to check if the key already exists in my set. If it does the score is added to the one existing. If not a new entry to the dictionary is created. This is very easy in Delphi but I'm having trouble in Objective-C. Keys and values are NSInteger. How can I do this? Something like this?:

if ([target_results objectForKey:[NSNumber numberWithInteger:temp]])
{
   //add to existing
   [target_results setObject:[NSNumber numberWithInteger:incoming_score + (...existing value...)] forKey:[NSNumber numberWithInteger:myKeyValue]];

 }
 else
 {
    //new entry
    (???)
 }
开发者_JAVA技巧


use an NSMutableDictionary and send it the setValue: forKey: message:

NSMutableDictionary *target_results;

[target_results setValue:incoming_score forKey:forKey:[NSNumber numberWithInteger:myKeyValue]]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜