存储NSArray在核心数据示例代码? [英] Store NSArray In Core Data Sample Code?
问题描述
我一直在寻找一些示例代码,如何存储一个 NSArray
在Core Data一段时间,但没有运气。有人会指点我一些教程或示例,或者更好地写一个简单的样本作为这个问题的答案?我已阅读此,但未显示如何实现一个 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!
推荐答案
如果你真的需要做,那么编码为数据。我只是创建了一个名为的新文件夹 c>作为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实现: / p>
Then in the NSManagedObject implementation:
-(void)setReceiveList:(NSArray*)list{
self.receive = [NSKeyedArchiver archivedDataWithRootObject:list];
}
-(NSArray*)getReceiveList{
return [NSKeyedUnarchiver unarchiveObjectWithData:self.receive];
}
这篇关于存储NSArray在核心数据示例代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!