Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

skunkworker

macrumors regular
Original poster
Sep 9, 2007
182
20
So i've got a nsdocument-based application that can have multiple documents open at a time.And I have a number of different views and data classes for managing everything.
It all works great until I try to create a shared instance that allows the other views to pull data and access the editordocument class
like

Code:
[[EditorDocument sharedInstance] editingState]



And in the main NSDocument class
Code:
EditorDocument *g_SharedInstance = nil;

+ (EditorDocument*) sharedInstance {
assert (g_SharedInstance != NULL);

if (g_SharedInstance == nil) {
g_SharedInstance = [EditorDocument alloc];
} 

return g_SharedInstance;
}
 
So, there's a few things wrong here. First and foremost: it's basically never correct to call +alloc without -init*. Secondarily: if you support multiple documents, how can you have the document stored in a single global variable?
 
So, there's a few things wrong here. First and foremost: it's basically never correct to call +alloc without -init*. Secondarily: if you support multiple documents, how can you have the document stored in a single global variable?

I have been trying to move it from a single document based to multiple document based.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.