• 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: Is NSDocument read outside init?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is NSDocument read outside init?


  • Subject: Re: Is NSDocument read outside init?
  • From: "Louis C. Sacha" <email@hidden>
  • Date: Thu, 15 Apr 2004 02:10:13 -0700

Hello...

I would recommend not overiding the init methods to do things that would be specific to a new or existing document. Instead, you could implement windowControllerDidLoadNib: and set up your document there. Once you get to that point, you should know if the document is supposed to be an untitled document or an existing document. Your override of init would call super and then do whatever basic initialization needs to be done for both types of documents. You could probably just leave the initWithContentsOf...:ofType: initializers alone.

NSDocument uses a different style for initializers than most of the other Cocoa classes. Instead of having the simple initializer call the more complicated ones with default arguments, the init method is the designated initializer. The initWithContentsOf...:ofType: initializers are for convienience and call init as part of their implementation, before reading in the file.

The only issue I can think of that might be a problem for using windowControllerDidLoadNib: is that it might never happen if the document is opened from the NSDocumentController and setShouldCreateUI: is set to FALSE. Whether that is a problem depends on how much your document model is seperated from the UI of the document (and if there is any chance that documents will be opened with the application set up that way).

Louis


Allan Odgaard wrote:
On 15. Apr 2004, at 7:19, Scott Anguish wrote:

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...

My "problem" is actually to differentiate between a new untitled document and a document read from disk.

Currently init is called in both cases -- so I need to act as if the document was untitled and then undo that in the following read method (if one is sent). And that is what I wanted to avoid (for various reasons).

However, reading the conceptual documentation, it would seem that setting a boolean value in an overloaded initWithContentsOfFile:ofType: (before calling super) is also a way for me to learn in which context the init method is called -- not that I am a fan of this solution, but I think I'll try that for now ;)

Thanks for the help.
_______________________________________________
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.


References: 
 >Is NSDocument read outside init? (From: Allan Odgaard <email@hidden>)
 >Re: Is NSDocument read outside init? (From: Scott Anguish <email@hidden>)
 >Re: Is NSDocument read outside init? (From: Allan Odgaard <email@hidden>)

  • Prev by Date: NSArrayController
  • Next by Date: 'Class' may not respond to +isKindOfClass
  • Previous by thread: Re: Is NSDocument read outside init?
  • Next by thread: Re: Is NSDocument read outside init?
  • Index(es):
    • Date
    • Thread