在核心数据示例代码中存储 NSArray? [英] Store NSArray In Core Data Sample Code?

查看:27
本文介绍了在核心数据示例代码中存储 NSArray?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一些关于如何在 Core Data 中存储 NSArray 的示例代码,但一直没有找到.有没有人介意给我指点一些教程或例子,或者更好地写一个简单的样本作为这个问题的答案?我已经阅读了 this 但它没有展示如何实现一个 NSArray 的可转换属性的示例.提前致谢!

I have been searching for some sample code on how to store an NSArray in Core Data for awhile now, but haven't had any luck. Would anyone mind pointing me to some tutorial or example, or better yet write a simple sample as an answer to this question? I have read this but it doesn't show an example of how to go about implementing a transformable attribute that is an NSArray. Thanks in advance!

推荐答案

如果你真的需要这样做,那么编码为数据.我只是创建了一个名为 receive 作为 NSData(二进制数据)的新文件.

If you really need to do it, then encode as data. I simply created a new filed called receive as NSData (Binary data).

然后在 NSManagedObject 实现中:

Then in the NSManagedObject implementation:

-(void)setReceiveList:(NSArray*)list{
     self.receive = [NSKeyedArchiver archivedDataWithRootObject:list];
}

-(NSArray*)getReceiveList{
    return [NSKeyedUnarchiver unarchiveObjectWithData:self.receive];
}

这篇关于在核心数据示例代码中存储 NSArray?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆