I'm using Core Data and I'm trying to figure out the simplest way to store an array of integers in one of my Core Data entities. Currently, my entities contain various arrays of objects that are more complex than a single number, so it makes sense to represent those arrays as tables in my DB and attach them using relationships. If I want to store a simple array of integers, do I need to create a new table with a single column and attach it using a one-to-many relationship? Or is there a more simple way?
Thanks in advance for your wisdom!
Chris Hanson already gave a good answer to this question, still if you really want to store the NSArray as Core Data attribute take a look at transformable attributes
For an array of integers, I would use a Binary property - which is an NSData. NSData has a lot of accessor/modifier methods. If you need/want to keep an mutable copy, then you can use NSMutableData as a cache - and persist that (as an NSData) as makes sense.
I use this for long lists of doubles - which, for me, represent collected data sets. This works for me because I have no need to link a single data point to some other object in my model. At runtime, I unpack these data sets and use them to render graph lines. At that point, I could generate some sort of relatedness - but that relatedness would need to be derived.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With