如何在 NSUserDefaults 中保存包含自定义对象的 NSMutableArrays 的 NSMutableArray

发布于 2024-09-27 11:17:53 字数 126 浏览 1 评论 0原文

通过在自定义类中实现 NSCoding,我能够将自定义对象的 NSMutableArray 保存到 NSUserDefaults。但是,现在我想保存这些数组的 NSMutableArray。当我尝试这样做时,编译器会抱怨。这怎么能做到呢?

I was able to save an NSMutableArray of custom objects to NSUserDefaults by implementing NSCoding in the custom class. However, now I want to save an NSMutableArray of these arrays. The compiler complains when I try to do this. How can this be done?

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

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

发布评论

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

评论(1

千寻… 2024-10-04 11:17:53

我知道怎么做了。基本上,您使用 NSKeyedArchiver 将数组转换为数据对象,这就是您使用 NSUserDefaults 保存的内容。然后,当您取回数据对象时,使用 NSKeyedUnarchiver 将其重新转换为数组。

I found out how to do it. Basically, your transform the array into a data object using NSKeyedArchiver, and that is what you save with NSUserDefaults. Then when you get the data object back, you use NSKeyedUnarchiver to turn it back into an array.

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