将对象 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
。
谢谢你的帮助。
佩德罗
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将其添加到数组中就好了 ^^ 您想要写入 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
佩德罗·皮涅拉·布恩迪亚,
试试这个代码,
Pedro Piñera Buendia,
Try this code,