How best to archive in CSV format
How best to archive in CSV format
- Subject: How best to archive in CSV format
- From: Denis Stanton <email@hidden>
- Date: Tue, 17 May 2005 08:51:48 +1200
Hi
I'm looking for advice on the best way to handle archiving my documents in csv (comma separated variable) format.
I have written a small Coca application to be used for data capture. The program accepts text and numbers typed into an NSTableView and stores them in an array of objects. Following the document-based application examples in Aaaron Hillegass' excellent book my app is able to archive the array to disk in a coded format. I have implemented encodeWithCoder and initWithCoder methods on the class that is stored in the array. My MyDocument class has dataRepresentationOfType: and loadDtaRepresentation:ofType: methods which use NSkeyedArchiver to save or retrieve documents.
That all works very nicely (thanks Aaron) but in order to be useful I need to change the document storage format to simple csv. Can I do this through the encodeWithCoder initWithCoder mechanism? This seems to me to be the logical place to write routines for transforming objects to and from a disk file but maybe I'm misunderstanding the function of NSCoder. Is it sensible to write a coder that converts objects to UTF strings?
What I have at the moment is an extra method inside my object that returns a string representation of the object by appending a description of each item to an NSMutableString. Then I have replaced the NSKeyedArchiver part of
dataRepresentationOfType: with a loop that retrieves this string from each item in the array and concatenates it into a bigger string which is then returned with
return [string dataUsingEncoding: NSUTF8StringEncoding];
The encodeWithCoder method is not being used.
This works, but it looks clumsy. I'm having doubts that it will scale as the string will grow very large. The init method for NSMutableString requires that I specify a capacity which it says is a "hint" of how much memory to allocate. I don't know how binding (no, not the Cooca sort of binding) a "hint" is. Am I free to exceed the capacity, or do I have to anticipate the maximum string size? These doubts make me think I'm going about this all wrong. Should I be using the encode and decode system to convert to and from csvs format?
regards
Denis
<x-tad-smaller>Denis Stanton
Orcon Internet Limited
(09) 480 9299
</x-tad-smaller><x-tad-smaller>http://www.orcon.net.nz
</x-tad-smaller><x-tad-smaller>
</x-tad-smaller> _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden