使用NSDictionaries插入NSMutableDictionary

时间:2010-08-19 20:51:08

标签: objective-c nsmutablearray

我尝试在NSDictionary中插入NSMutableDictionary。没有错误但它不起作用,它仍然是空的。

这是我的代码:

NSMutableDictionary *einnahmen = [[NSMutableDictionary alloc] initWithCapacity:20];
NSArray *objects = [NSArray arrayWithObjects:
            name, 
            [NSNumber numberWithInt: x], 
            [NSNumber numberWithInt: y], 
            [NSNumber numberWithInt: z], 
            nil];
NSArray *keys = [NSArray arrayWithObjects:
                     @"name", 
                     @"startJahr",
                     @"zins", 
                     @"entnahmefaehig",
                     nil];
NSDictionary *entry = [NSDictionary dictionaryWithObjects:objects forKeys:keys];

[einnahmen setObject:entry forKey:@"name"]; //seems not to work

调试器显示[einnahmen setObject:entry之后:

alt text

1 个答案:

答案 0 :(得分:2)

我已经解决了这个问题。以下代码使用了错误的init-method:

NSMutableDictionary *einnahmen = 
              [[NSMutableDictionary alloc] initWithCapacity:20];

编译器应显示错误。