-2

I have a core data table with three attributes (all strings) and i want to out put the entire table to a CSV file to then be emailed.

I have looked at the following questions

Export Core Data Entity as text files in Cocoa

How to export Core Data entity to a CSV file

but i have not been able to work anything into a solution. I am really short of time to go through apple doc's to work it out, so was hoping some ones could give me a quick and easy solution.

edit:

after further research i found this post Exporting the core data into csv via mail composer using CHCSVParser(by Dave DeLong)

my problem is now solved! CHCSV is my new best friend!

Community
  • 1
  • 1
joffd
  • 521
  • 5
  • 19
  • Core Data is an object graph abstraction layer over different storage backends - so it doesn't really have tables. Can you elaborate on your question to make it clear what you mean by "table" in this case? – quellish May 12 '14 at 23:16
  • I have one entity with 3 attributes all strings – joffd May 12 '14 at 23:52

1 Answers1

0

No, core data doesn't give you that feature out of the box. Lucky for you, it's a fairly simple process given the fact that your entity only has three attributes. So, create the file for exportation (you can use something like NSFileHandle, or whatever file writing technique you're confortable with),create your NSFetchRequest instance with the proper sort order you want, and enumerate all objects it returned. Once you receive all objects, write it to file with the order you need for your csv file. Here's some links for resources you can use:

NSFetchRequest

NSFileHandle

NSFileManager

J2theC
  • 4,412
  • 1
  • 12
  • 14