I&#39;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:<div>
<br></div><div><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1038.35">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4e8186}
span.s1 {color: #bb2d9d}
span.s2 {color: #000000}
span.s3 {color: #3e1f7c}
span.s4 {color: #4e8186}
span.Apple-tab-span {white-space:pre}
</style>


<p class="p1"><span class="s1">static</span> MyDocument* sharedDocument;</p>
<p class="p2"><br></p>
<p class="p1">- (<span class="s1">id</span>)init </p>
<p class="p1">{</p>
<p class="p3"><span class="s2"><span class="Apple-tab-span">        </span></span><span class="s1">if</span><span class="s2">(!</span>sharedDocument<span class="s2">)</span></p>
<p class="p1"><span class="Apple-tab-span">        </span>{</p>
<p class="p1"><span class="Apple-tab-span">        </span><span class="Apple-tab-span">        </span><span class="s1">self</span> = [<span class="s1">super</span> <span class="s3">init</span>];</p>
<p class="p2"><span class="Apple-tab-span">        </span><span class="Apple-tab-span">        </span></p>
<p class="p1"><span class="Apple-tab-span">        </span><span class="Apple-tab-span">        </span><span class="s1">if</span> (<span class="s1">self</span> != <span class="s1">nil</span>) {</p>
<p class="p3"><span class="s2"><span class="Apple-tab-span">        </span><span class="Apple-tab-span">        </span><span class="Apple-tab-span">        </span></span>sharedDocument<span class="s2">=</span><span class="s1">self</span><span class="s2">;</span></p>

<p class="p1"><span class="Apple-tab-span">        </span><span class="Apple-tab-span">        </span>}</p>
<p class="p1"><span class="Apple-tab-span">        </span>}</p>
<p class="p2"><span class="Apple-tab-span">        </span></p>
<p class="p3"><span class="s2">    </span><span class="s1">return</span><span class="s2"> </span>sharedDocument<span class="s2">;</span></p>
<p class="p1">}</p>
<p class="p2"><br></p>
<p class="p1">+(<span class="s4">MyDocument</span>*)sharedDocument</p>
<p class="p1">{</p>
<p class="p3"><span class="s2"><span class="Apple-tab-span">        </span></span><span class="s1">if</span><span class="s2">(!</span>sharedDocument<span class="s2">)</span></p>
<p class="p1"><span class="Apple-tab-span">        </span>{</p>
<p class="p3"><span class="s2"><span class="Apple-tab-span">        </span><span class="Apple-tab-span">        </span>[[</span>MyDocument<span class="s2"> </span><span class="s3">alloc</span><span class="s2">] </span><span class="s3">init</span><span class="s2">];</span></p>

<p class="p1"><span class="Apple-tab-span">        </span>}</p>
<p class="p2"><span class="Apple-tab-span">        </span></p>
<p class="p3"><span class="s2"><span class="Apple-tab-span">        </span></span><span class="s1">return</span><span class="s2"> </span>sharedDocument<span class="s2">;</span></p>
<p class="p1">}</p></div><div><br></div><div><div><span class="Apple-tab-span" style="white-space:pre">A</span>nd here is how I implemented this.  I&#39;m not sure if this is the best solution.  I&#39;m concerned there will be a leak, though I have not looked yet.  Any suggestions are appreciated.</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>public MyDocument (IntPtr handle) : base(SharedDocument == null ? handle : SharedDocument.Handle)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>if (SharedDocument == null)</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>SharedDocument = this;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div></div><div><br></div><div><br></div><div>Thanks,</div><div>Duane</div>