I think this is pretty simple but i’m new to Objective-C, IOS and Core Data.
I have a Core Data entity called EnquiryStore, which contains various attributes “name”, “address”, “enquiry” etc..
I can fetch the results fine but I struggling to understand how the results are stored! Which is making it hard for me to do the next part of my program which is to export the data to CSV using Dave DeLong’s CHCSVWriter. I understand that to use
[array writeToCSVFile:outputCSVFile atomically: NO];
It will accept an Array of Arrays, is this what Core Data gives me? Because i can’t get it to work with that method.
I could use
[myCSVWriter writeField: ...];
[myCSVWriter writeLine];
but this seems long winded as I will have to build the string from each attribute from Core Data.
You are the only person that knows how your NSManagedObject looks like, it could have relationships which would be impossible to put in a csv file. It could have binary data which would not be very useful in a csv file. Or it just could have attributes that you don’t want to export. And you have to decide in which order you want your csv exported too.
It’s easy to create a NSArray (ie the list of NSManagedObjects you want to export) of NSArray (ie the list of exported attributes for that object). Just enumerate through all your NSManagedObject and fill an array with the values you want to export.
You could use something like this:
and there you have your array of arrays.
I believe there was a method that returned an NSArray of values if you pass it a NSArray of keys, but I can not find it, and I can’t remember its name or even to which class it belonged.