Re: Simple File Data Reading Question
Re: Simple File Data Reading Question
- Subject: Re: Simple File Data Reading Question
- From: Dustin Voss <email@hidden>
- Date: Tue, 10 Feb 2004 16:44:40 -0800
On 9 Feb, 2004, at 11:09 PM, Sam Daniel wrote:
What is the specific code using
(BOOL)readFromFile:(NSString *)fileName ofType(NSString *)docType
to retrieve 3 integer numbers (separated by white space) in a single
line text file and place them into an NSArray?
The framework calls "readFromFile:ofType:" to open a document. It calls
this method as one step in its default process of opening a document,
which ends up with an exception. For the opening process to work, you
have to make a subclass of NSDocument and override some methods.
If the entire document consists of just the one line of text as you
describe, you do not need to override "readFromFile:ofType:". You
should instead override "loadDataRepresentation:ofType:". In this
method, you will get an NSData (the contents of the file, in your case,
a line of text), from which you must extract your document data (in
your case, the three integers). The document data will generally go in
the member variables of your NSDocument subclass.
At any rate, if it was me implementing this, I would take the NSData,
convert it to an NSString, use sscanf([fileString UTF8String], "%d %d
%d", ...) to read into three local variables, and, lastly, I would
convert the variables to NSNumbers and create the NSArray.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.