Re: Write to a text file
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.