将对象NSMutableArray添加到NSDictionary

时间:2011-10-11 08:42:37

标签: iphone ios arrays nsmutablearray nsdictionary

我正在尝试向NSMutableArray添加NSDictionary,但在日志中显示NSDictionary时出现此问题:

)' of class '__NSCFArray'.  Note that dictionaries and arrays in
property lists must also contain only property valúes.

这是我用来创建NSMutableDictionary

的代码
NSMutableDictionary *training = [[NSMutableDictionary alloc] init];
[training setObject:[NSNumber numberWithInt:eltiempo] forKey:@"tiempototal"];
[training setObject:[NSNumber numberWithFloat:totalkm] forKey:@"distanciatotal"];
[training setObject:[NSNumber numberWithInt:(int)(velocidadmedia/60)] forKey:@"velocidadmedia"];
[training setObject:[NSString stringWithFormat:@"%2d:%02d min/km"] forKey:@"fecha"];
[training setObject:posiciones forKey:@"posiciones"];

posiciones是我要添加的数组。我将此字典保存在一个数组中,以便将其保存在用户默认值中。但是由于我遇到了这个问题,NSDictionary没有被创建。

谢谢你的帮助。

佩德罗

2 个答案:

答案 0 :(得分:0)

你把它添加到数组中就好^^你要写一个plist(根据错误)和posiciones包含不能在plist中使用的非plist类型

答案 1 :(得分:-5)

PedroPiñeraBuendia,

试试这段代码,

NSMutableDictionary *woRows = [[NSMutableDictionary alloc] init];
NSMutableArray *workOrders = [[NSMutableArray alloc] init];

[woRows  setValue:[workOrders objectAtIndex:0] forKey:@"somekey"];
[woRows setValue:[workOrders objectAtIndex:1] forKey:@"somekey"];
[woRows setValue:[workOrders objectAtIndex:2] forKey:@"somekey"];