Re: Is NSDocument read outside init?
Re: Is NSDocument read outside init?
- Subject: Re: Is NSDocument read outside init?
- From: Scott Anguish <email@hidden>
- Date: Thu, 15 Apr 2004 01:19:03 -0400
On Apr 14, 2004, at 9:55 PM, Allan Odgaard wrote:
Since I override initWithContentsOfFile:ofType: in an NSDocument
subclass, I was curious to wether or not I need to implement any of
the read methods?
The Reference docs say...
Initializes and returns an NSDocument object of document type docType
containing data stored in the file fileName. If the file cannot be
opened, displays an attention panel informing the user and then returns
nil. In opening the file, invokes the readFromFile:ofType: method. If
the document successfully opens the file, it calls setFileName: and
setFileType: with fileName and docType, respectively, as arguments.
This initializer is typically invoked by NSDocumentControllers
makeDocumentWithContentsOfFile:ofType:.
and the Conceptual docs
(
http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/
Tasks/SubclassNSDocument.html#//apple_ref/doc/uid/20000028) say
The initializers of NSDocument are another issue for subclassers. The
init method is the primary initializer, and it is invoked by the other
initializer initWithContentsOfFile:ofType:. The init method is directly
invoked when a new document is created; the
initWithContentsOfFile:ofType: method is directly invoked when a
document is opened. Therefore if you have any initializations that
apply only to documents that are opened, you should override
initWithContentsOfFile:ofType:; if you have general initializations,
you should, of course, override init. In both cases, be sure to invoke
supers implementation as the first thing.
It would seem to me that these are only sent from the initializer (and
revertToSavedFromFile:ofType:), is this assumption safe?
It'd be better to do the read in the read method, and just do any
additional initialization you need to with
initWithContentsOfFile:ofType:. It gives you the opportunity of doing
anything special for a particular file type, but it's not a replacement
for loading the data...
Likewise, are any of the URL methods used by default? both NSDocument
and NSDocumentController can/does deal with URLs, but the various
application delegate methods can only deal with filenames, which seems
to be a bit of a show stopper -- I did once try to send a non-file URL
to noteNewRecentDocumentURL:, but that did not work very well.
I'm not sure that non-file URLs are supported here... I suppose if you
implement the URL read/write methods they could be (my guess is that it
falls back to the file versions if you don't)..
I've filed a request for clarifying the docs.
_______________________________________________
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.