简体   繁体   中英

NSMutableArray of NSString in CoreData(iPhone

I have a class, which describe an object for parsing XML. This class contains NSStrings and NSMutableArrays 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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM