开发者

NSMutableArray of NSString in CoreData(iPhone

开发者 https://www.devze.com 2023-01-01 04:51 出处:网络
I have a class, which describe an object for parsing XML. This class contains NSStrings and NSMutab开发者_高级运维leArrays of NSStrings.I want to store parsed data using CoreData.How should I write Co

I have a class, which describe an object for parsing XML. This class contains NSStrings and NSMutab开发者_高级运维leArrays of NSStrings.I want to store parsed data using CoreData. How should I write CoreData model to store such objects if there is no such data type like NSMutableArray? Is there any way?


You can create two entities, I'll call them Array and String. Array has one relationship, strings, which is a one-to-many relationship with the String entity. The String entity then has one attribute, I'll call it string too, which actually is a string and contains the value you need. This will allow you to store them as a set, if the order is important add another attribute to the String entity called order and make it a number.


There isnt an array data type, but u can box the string in a core data object (lets call it A for the remainder of the post). Then in the object (B) which you want to have the array of string (that persists) in just make a to-many relationship with the object A which contains the string, then youll have a Set of string on the object B which you can turn into an array and do with what you like. hope that helps

0

精彩评论

暂无评论...
验证码 换一张
取 消