"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 a开发者_如何学JAVAgain)
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:
- Does it make sense to put the model in the MainMenu.xib and how can I access it from
MyDocument.m
- Is there maybe a better way to do this properly without having to make a singleton class?
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.
I finally got it working with my NSApplication subclass (some say this is not the way to go). For this I had to change the principal class from NSApplication
to my new custom NSApplication subclass.
精彩评论