Search code examples
objective-cxcodemacosnsdocument

"Global" model in NSDocument-based application


I have a NSDocument based application, which allows the user to send messages, after he has logged in.

These should be the user's steps:

  • The user starts the App and logs in (credentials are stored in the user model)
  • The user user sends the first message
  • The user hits CMD + N and sends another message (without having to log in again)

The message model is placed in the MyDocument.xib. However the user model should be place in a global place (I would say MainMenu.xib).

My question is now:

  1. Does it make sense to put the model in the MainMenu.xib and how can I access it from MyDocument.m
  2. Is there maybe a better way to do this properly without having to make a singleton class?

Solution

  • I would create an NSApplication delegate and then add you functionality in you delegate or an property of you delegate, you can then use [[NSApplicaton sharedApplicaton] delegate] to get you delegate. You application delegate is the place to associate model data that is common to you application.