• 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: NSPersistentDocument initForURL:withContentsOfURL
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPersistentDocument initForURL:withContentsOfURL


  • Subject: Re: NSPersistentDocument initForURL:withContentsOfURL
  • From: mmalcolm crawford <email@hidden>
  • Date: Mon, 26 Sep 2005 18:37:22 -0700


On Sep 26, 2005, at 12:36 PM, Mu Lin wrote:
I am using NSPersistentDocument. I overrided initWithType as such to provide some initial contents for newly created documents:
- (id)initWithType:(NSString *)typeName error:(NSError **)outError
{
NSURL *tempURL = [NSURL URLWithString:@"file://localhost/Users/ SomeBody/Desktop/defaultFile"];
return [self initForURL:nil /* using nil here to get "untitled" and "untitled 2" file display name. */
withContentsOfURL:tempURL
ofType:@"XML"
error:outError];
}
It works fine during the opening but when I save the documents to another file such as "myFile2" using "save as..", the "defaultFile" was blown away. How can I get around of this behavior?


You can't get around it -- that's how it's designed to operate (and "repurposing" initialisers like that is generally a bad idea...).
There are several ways to do what you want: Probably the easiest way (*) is to store the default objects in a property list (as an array) and create and initialise managed objects from the array using key- value coding.


mmalc
(*) Using a second, read-only, store, you might run into a bug that will make things more difficult.


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSPersistentDocument initForURL:withContentsOfURL (From: "Mu Lin" <email@hidden>)

  • Prev by Date: NSTextInput, multi-character marks, and the cursor position
  • Next by Date: Re: CD: subclassing NSArrayController
  • Previous by thread: NSPersistentDocument initForURL:withContentsOfURL
  • Next by thread: Determining current language
  • Index(es):
    • Date
    • Thread