Re: [newbie] Saving text from NSTextView
Re: [newbie] Saving text from NSTextView
- Subject: Re: [newbie] Saving text from NSTextView
- From: Jeremy Dronfield <email@hidden>
- Date: Thu, 12 Sep 2002 14:01:56 +0100
On Thursday, September 12, 2002, at 01:32 pm, Mark Woollard wrote:
[text writeToFile:file automatically:NO];
However at runtime I get the following output:
002-09-12 13:29:35.510 SpamWeasel Pro[6788] *** -[NSBigMutableString
writeToFile:automatically:]: selector not recognized
Any pointers on what's going on?
Well, start by changing "automatically" to "atomically". There's no such
method as -writeToFile:automatically:.
It's generally advisable to set the atomically argument to YES, since
it's a safety measure to prevent data loss in the event of a crash
during saving (it writes data to an auxiliary file before overwriting
any original file).
Another point is that it's a common practice to enclose -writeToFile: in
an IF statement (the method returns a boolean, so this is dead simple),
so you can inform the user if the save goes wrong, like so:
- (void)saveMyData
{
if (![text writeToFile:file atomically:YES]) {
NSBeginCriticalAlertSheet(@"Couldn't write data.", @"OK",
nil, nil, [self window], self, NULL, NULL, NULL, @"The file or folder
might be protected against writing.");
}
}
-Jeremy
========================================
email@hidden // email@hidden
The Alchemy Pages:
- fractious fiction at
http://freespace.virgin.net/jeremy.dronfield
========================================
_______________________________________________
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.