• 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: Write to a text file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Write to a text file


  • Subject: Re: Write to a text file
  • From: "Ben O'Neill" <email@hidden>
  • Date: Mon, 6 May 2002 17:25:44 +1000

Thanks Nathan,
Thats helped me, but when I use the below code:

{
NSString *temp = titleField;
[temp writeToFile: @"/ben.txt" atomically: YES];
}

I get this error message:

2002-05-06 17:24:02.948 DVD Manager[1939] *** -[NSTextField writeToFile:atomically:]: selector not recognized

Do you know what is missing?
Thanks
Ben.

On Monday, May 6, 2002, at 01:44 PM, Nathan Zamecnik wrote:

On 5/5/02 10:19 PM, "Ben O'Neill" <email@hidden> wrote:

Hello,
I am new to Cocoa and C development.
I want to write a text field to a text file when I click the save
button. I have been trying to use the NSFileHandle object and writeData
however, I can't seem t get it to write the file. Is this the correct
approach? Does anyone have some sample code?

Others have suggested writing my text to an XML file, is this a better
approach if I want to save records with fields in a text file?
Kind Regards
Ben
_______________________________________________
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.

All you have to do is use a method form the NSstring class. Here is the
most basic way to write a string to a file:
[theStringInstance writeToFile:@"Give path here" atomically:YES]
That is all you need to do. Careful though as this will overwrit what is at
that location. I suggest reading the NSString documentation for this to
learn more about it. Also, look into the NSSavePanal class in the AppKit.
That way the user can select where they are going to save and you can write
to that path. Hope this helps a bit.
BTW, the name of the file will be what you set it to, like this:
@"/Users/yourName/directory/theFileName.txt"
That will create a file named FileName.txt

-- NAteZ
_______________________________________________
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.

  • Follow-Ups:
    • Re: Write to a text file
      • From: Ondra Cada <email@hidden>
    • Re: Write to a text file
      • From: Thomas Lachand-Robert <email@hidden>
    • Re: Write to a text file
      • From: Timothy Larkin <email@hidden>
References: 
 >Re: Write to a text file (From: Nathan Zamecnik <email@hidden>)

  • Prev by Date: Re: [OT] about Apache Folder; and graphics algorithms
  • Next by Date: Action is not recognized
  • Previous by thread: Re: Write to a text file
  • Next by thread: Re: Write to a text file
  • Index(es):
    • Date
    • Thread