• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Simple File Data Reading Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.
References: 
 >Simple File Data Reading Question (From: Sam Daniel <email@hidden>)

  • Prev by Date: Re: Getting an NSString out of an NSTextView;
  • Next by Date: Re: Making the correct button the default button?
  • Previous by thread: Re: Simple File Data Reading Question
  • Next by thread: Re: Simple File Data Reading Question
  • Index(es):
    • Date
    • Thread