[Mono-osx] [MonoMac] shared NSDocument
Duane Wandless
duane at wandless.net
Sun Jan 16 11:02:41 EST 2011
I'm trying to create a Document based app. I need to share MyDocument
across multiple view controller NIBs. So in each NIB I add an NSDocument
object then change the class to be MyDocument. As each VC is loaded a new
MyDocument object is created. However this is incorrect we want the initial
MyDocument object to be used. In the obj-c app we have this is being done:
static MyDocument* sharedDocument;
- (id)init
{
if(!sharedDocument)
{
self = [super init];
if (self != nil) {
sharedDocument=self;
}
}
return sharedDocument;
}
+(MyDocument*)sharedDocument
{
if(!sharedDocument)
{
[[MyDocument alloc] init];
}
return sharedDocument;
}
And here is how I implemented this. I'm not sure if this is the best
solution. I'm concerned there will be a leak, though I have not looked yet.
Any suggestions are appreciated.
public MyDocument (IntPtr handle) : base(SharedDocument == null ? handle :
SharedDocument.Handle)
{
if (SharedDocument == null)
{
SharedDocument = this;
}
}
Thanks,
Duane
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20110116/5a5204c9/attachment.html
More information about the Mono-osx
mailing list