我有一组数据,不需要成为托管列表,这意味着我不需要Realm为具有链接的项目创建新模型,并且能够查询项目等。我只是想要一个简单的数组,通常是不会从Object继承的基元,这些基元将被我的主对象持久化。
我能想到的唯一解决方案是使用NSData和NSKeyedArchiver / NSKeyedUnarchiver。 这是最好的/唯一的方法来做到这一点? 即使我不认为我需要它,我也应该使用List吗?这种情况的最佳做法是什么?
I have an array of data that doesn't need to be a managed List, meaning I don't need Realm to create a new model for the items with links and the ability to query on the items, etc. I just want a simple array, typically of primitives that don't inherit from Object anyway, that will be persisted with my main object.
The only solution I can think of is to use NSData and NSKeyedArchiver/NSKeyedUnarchiver. Is that the best/only way to do this? Should I just use List even if I don't think I'll need it — what's the best practice for this situation?
最满意答案
Realm不支持原始数组(尽管该功能即将推出),所以最直接的解决方案是使用充满模型对象的List来包装原始数据。 如果您觉得更适合您的特定用例,那么将NSData存档并从NSData归档并将数据存储在Realm模型中没有任何问题。
Realm doesn't support arrays of primitives (although that functionality is coming soon), so the most straightforward solution is to use a List filled with model objects that just wrap your primitives. There's nothing wrong with archiving to and from NSData and storing the data in your Realm model, though, if you feel that better suits your particular use case.
更多推荐
发布评论