Re: NSPersistentDocument initForURL:withContentsOfURL
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