将对象 NSMutableArray 添加到 NSDictionary

发布于 2024-12-09 02:30:57 字数 930 浏览 1 评论 0原文

我正在尝试将 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

谢谢你的帮助。

佩德罗

I am trying to add an NSMutableArray to an NSDictionary but I get this issue when show NSDictionary in log:

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

This is the code I use to create the 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"];

Where posiciones is the array I want to add. I save this dictionary in an array in order to save it in User Defaults. But as I have this problem the NSDictionary is no created.

Thanks for you help.

Pedro

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

日久见人心 2024-12-16 02:30:57

您将其添加到数组中就好了 ^^ 您想要写入 plist (根据错误)并且 posiciones 包含不能在 plist 中使用的非 plist 类型

you add it to the array just fine ^^ you want to write to a plist (according to the error) and posiciones contains non-plist types that cannot be used in a plist

夜唯美灬不弃 2024-12-16 02:30:57

佩德罗·皮涅拉·布恩迪亚,

试试这个代码,

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"];

Pedro Piñera Buendia,

Try this code,

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"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文