• 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: [newbie] Saving text from NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: [newbie] Saving text from NSTextView
      • From: Ondra Cada <email@hidden>
References: 
 >[newbie] Saving text from NSTextView (From: Mark Woollard <email@hidden>)

  • Prev by Date: Re: [newbie] NSString code so it won't leak
  • Next by Date: Re: Start using Cocoa
  • Previous by thread: Re: [newbie] Saving text from NSTextView
  • Next by thread: Re: [newbie] Saving text from NSTextView
  • Index(es):
    • Date
    • Thread