<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Multiple Windows with Core Data</title>
	<atom:link href="http://www.timisted.net/blog/archive/multiple-windows-with-core-data/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.timisted.net/blog/archive/multiple-windows-with-core-data/</link>
	<description>Cocoa Programming and Other Things</description>
	<lastBuildDate>Mon, 19 Sep 2011 03:07:11 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
	<item>
		<title>By: Bill</title>
		<link>http://www.timisted.net/blog/archive/multiple-windows-with-core-data/comment-page-1/#comment-10230</link>
		<dc:creator>Bill</dc:creator>
		<pubDate>Sun, 16 Jan 2011 04:42:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.timisted.net/blog/?p=3#comment-10230</guid>
		<description>This post was great in helping me understand NSWindowControllers MUCH better. Thanks!
I did need to bind the popups selected value to &#039;Person selection department.name&#039; otherwise the popup text was set to Not Selected.

This was with XCode 3.1.2 on 10.5.</description>
		<content:encoded><![CDATA[<p>This post was great in helping me understand NSWindowControllers MUCH better. Thanks!<br />
I did need to bind the popups selected value to &#8216;Person selection department.name&#8217; otherwise the popup text was set to Not Selected.</p>
<p>This was with XCode 3.1.2 on 10.5.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.timisted.net/blog/archive/multiple-windows-with-core-data/comment-page-1/#comment-7842</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Sun, 28 Nov 2010 10:06:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.timisted.net/blog/?p=3#comment-7842</guid>
		<description>No, I use an underscore as a prefix for &lt;em&gt;all&lt;/em&gt; my instance variables. This means I can tell instantly in a method whether I&#039;m accessing an instance variable, or a local variable:

&lt;pre lang=&quot;objc&quot;&gt;
- (void)someMethod {
    if( [_person age] == 21 ) { // do something }
}
&lt;/pre&gt;

In this example, it&#039;s obvious I&#039;m accessing the instance variable directly, when I should probably be doing this:

&lt;pre lang=&quot;objc&quot;&gt;
- (void)someMethod {
    if( [[self person] age] == 21 ) { // do something }
}
&lt;/pre&gt;

If my instance variable was just named &lt;code&gt;person&lt;/code&gt;, it wouldn&#039;t be so obvious.

Different developers use different ways to name their instance variables. Some use conventions such as &lt;code&gt;m_person&lt;/code&gt; (&#039;m&#039; for member variable), others have the underscore on the end rather than the beginning. 

I&#039;ve heard differing interpretations of Apple&#039;s official advice on this convention. One thing that they definitely recommend against is using an underscore on the front of a &lt;em&gt;method&lt;/em&gt; name (e.g., if it&#039;s not defined in the class&#039;s public interface so is a &#039;private&#039; method that should only be called from within another method in the same class). Apart from anything else, this is the convention they use for their own internal &quot;Private API.&quot; If you&#039;re submitting App Store apps with classes that use underscore-prefixed methods, you run the risk of being flagged for using forbidden Private API, even if you&#039;re only using your own methods.</description>
		<content:encoded><![CDATA[<p>No, I use an underscore as a prefix for <em>all</em> my instance variables. This means I can tell instantly in a method whether I&#8217;m accessing an instance variable, or a local variable:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>someMethod <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span>_person age<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #2400d9;">21</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span> <span style="color: #11740a; font-style: italic;">// do something }</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>In this example, it&#8217;s obvious I&#8217;m accessing the instance variable directly, when I should probably be doing this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>someMethod <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self person<span style="color: #002200;">&#93;</span> age<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #2400d9;">21</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span> <span style="color: #11740a; font-style: italic;">// do something }</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>If my instance variable was just named <code>person</code>, it wouldn&#8217;t be so obvious.</p>
<p>Different developers use different ways to name their instance variables. Some use conventions such as <code>m_person</code> (&#8216;m&#8217; for member variable), others have the underscore on the end rather than the beginning. </p>
<p>I&#8217;ve heard differing interpretations of Apple&#8217;s official advice on this convention. One thing that they definitely recommend against is using an underscore on the front of a <em>method</em> name (e.g., if it&#8217;s not defined in the class&#8217;s public interface so is a &#8216;private&#8217; method that should only be called from within another method in the same class). Apart from anything else, this is the convention they use for their own internal &#8220;Private API.&#8221; If you&#8217;re submitting App Store apps with classes that use underscore-prefixed methods, you run the risk of being flagged for using forbidden Private API, even if you&#8217;re only using your own methods.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://www.timisted.net/blog/archive/multiple-windows-with-core-data/comment-page-1/#comment-7804</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Sat, 27 Nov 2010 17:37:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.timisted.net/blog/?p=3#comment-7804</guid>
		<description>Ok, so &quot;assign&quot; can be used to create weak referenced setters.  One more question, is the underscore character at the beginning of the variable names a standard practice when defining an instance that will only have weak references?</description>
		<content:encoded><![CDATA[<p>Ok, so &#8220;assign&#8221; can be used to create weak referenced setters.  One more question, is the underscore character at the beginning of the variable names a standard practice when defining an instance that will only have weak references?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.timisted.net/blog/archive/multiple-windows-with-core-data/comment-page-1/#comment-7510</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Sat, 20 Nov 2010 10:55:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.timisted.net/blog/?p=3#comment-7510</guid>
		<description>A weak reference is one that isn&#039;t retained. The setter for &lt;code&gt;person&lt;/code&gt;, for example uses this:
&lt;pre lang=&quot;objc&quot;&gt;
- (void)setPerson:(NSManagedObject *)value {
	_person = value;
}
&lt;/pre&gt;

A strong reference would effectively be doing this:
&lt;pre lang=&quot;objc&quot;&gt;
- (void)setPerson:(NSManagedObject *)value {
	_person = [value retain];
}
&lt;/pre&gt;

though in reality, this kind of setter obviously needs to release the previous value (to avoid a memory leak), after making sure it isn&#039;t the same as the new one (otherwise a &lt;code&gt;release&lt;/code&gt; on what you think is the old object will actually release the new object before you can re-retain it). 

There are various different styles of setter method, e.g.: 
&lt;pre lang=&quot;objc&quot;&gt;
- (void)setPerson:(NSManagedObject *)value {
	if( _person == value ) return;

        [_person release];
        _person = [value retain];
}
&lt;/pre&gt;
or
&lt;pre lang=&quot;objc&quot;&gt;
- (void)setPerson:(NSManagedObject *)value {
	[_person autorelease];
	_person = [value retain];
}
&lt;/pre&gt;

If I were writing this post today, I&#039;d use &lt;code&gt;@property&lt;/code&gt; and &lt;code&gt;@synthesize&lt;/code&gt; instead of including getter/setter methods:

(in the header file)
&lt;pre lang=&quot;objc&quot;&gt;@property (nonatomic, assign) NSManagedObject *person;&lt;/pre&gt;

(in the implementation file)
&lt;pre lang=&quot;objc&quot;&gt;@synthesize person = _person;&lt;/pre&gt;

The &lt;code&gt;assign&lt;/code&gt; indicates a weak reference on an object; replacing &lt;code&gt;assign&lt;/code&gt; with &lt;code&gt;retain&lt;/code&gt; would make it a strong one.</description>
		<content:encoded><![CDATA[<p>A weak reference is one that isn&#8217;t retained. The setter for <code>person</code>, for example uses this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setPerson<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSManagedObject</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>value <span style="color: #002200;">&#123;</span>
	_person <span style="color: #002200;">=</span> value;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>A strong reference would effectively be doing this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setPerson<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSManagedObject</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>value <span style="color: #002200;">&#123;</span>
	_person <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>value retain<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>though in reality, this kind of setter obviously needs to release the previous value (to avoid a memory leak), after making sure it isn&#8217;t the same as the new one (otherwise a <code>release</code> on what you think is the old object will actually release the new object before you can re-retain it). </p>
<p>There are various different styles of setter method, e.g.:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setPerson<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSManagedObject</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>value <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> _person <span style="color: #002200;">==</span> value <span style="color: #002200;">&#41;</span> <span style="color: #a61390;">return</span>;
&nbsp;
        <span style="color: #002200;">&#91;</span>_person release<span style="color: #002200;">&#93;</span>;
        _person <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>value retain<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>or</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setPerson<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSManagedObject</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>value <span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>_person autorelease<span style="color: #002200;">&#93;</span>;
	_person <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>value retain<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>If I were writing this post today, I&#8217;d use <code>@property</code> and <code>@synthesize</code> instead of including getter/setter methods:</p>
<p>(in the header file)</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, assign<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSManagedObject</span> <span style="color: #002200;">*</span>person;</pre></div></div>

<p>(in the implementation file)</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@synthesize</span> person <span style="color: #002200;">=</span> _person;</pre></div></div>

<p>The <code>assign</code> indicates a weak reference on an object; replacing <code>assign</code> with <code>retain</code> would make it a strong one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://www.timisted.net/blog/archive/multiple-windows-with-core-data/comment-page-1/#comment-7500</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Sat, 20 Nov 2010 04:35:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.timisted.net/blog/?p=3#comment-7500</guid>
		<description>One thing I don&#039;t understand is where you say that _person and _moc are being set as weak references.  Those setters don&#039;t look any different than a normal setter, so what&#039;s making them weak references?</description>
		<content:encoded><![CDATA[<p>One thing I don&#8217;t understand is where you say that _person and _moc are being set as weak references.  Those setters don&#8217;t look any different than a normal setter, so what&#8217;s making them weak references?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.timisted.net/blog/archive/multiple-windows-with-core-data/comment-page-1/#comment-6882</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Thu, 04 Nov 2010 23:13:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.timisted.net/blog/?p=3#comment-6882</guid>
		<description>Absolutely; just pass around the managed object context from the application delegate instead of the document controller. You&#039;ll obviously need to create and keep track of multiple window controllers yourself, though, rather than using &lt;code&gt;NSDocumentController&lt;/code&gt;&#039;s default behavior and &lt;code&gt;makeWindowControllers&lt;/code&gt; method.</description>
		<content:encoded><![CDATA[<p>Absolutely; just pass around the managed object context from the application delegate instead of the document controller. You&#8217;ll obviously need to create and keep track of multiple window controllers yourself, though, rather than using <code>NSDocumentController</code>&#8216;s default behavior and <code>makeWindowControllers</code> method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Flavio Donadio</title>
		<link>http://www.timisted.net/blog/archive/multiple-windows-with-core-data/comment-page-1/#comment-6841</link>
		<dc:creator>Flavio Donadio</dc:creator>
		<pubDate>Thu, 04 Nov 2010 04:06:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.timisted.net/blog/?p=3#comment-6841</guid>
		<description>Would these techniques work with a non-document-based CoreData application?</description>
		<content:encoded><![CDATA[<p>Would these techniques work with a non-document-based CoreData application?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CoreData 简介 &#124; Geeklu.com</title>
		<link>http://www.timisted.net/blog/archive/multiple-windows-with-core-data/comment-page-1/#comment-4943</link>
		<dc:creator>CoreData 简介 &#124; Geeklu.com</dc:creator>
		<pubDate>Sat, 25 Sep 2010 04:59:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.timisted.net/blog/?p=3#comment-4943</guid>
		<description>[...] CoreData有大量的特性，诸如支持Redo，Undo的功能，这些很多Document based的程序中显得非常的有用。 提供数据model结构变化轻量级的迁移方案。 CoreData还通过Binding特性和控件的紧密结合，这样使得只需要少量的代码便可以完成强大的功能，下面是一个例子 http://www.timisted.net/blog/archive/multiple-windows-with-core-data/ [...]</description>
		<content:encoded><![CDATA[<p>[...] CoreData有大量的特性，诸如支持Redo，Undo的功能，这些很多Document based的程序中显得非常的有用。 提供数据model结构变化轻量级的迁移方案。 CoreData还通过Binding特性和控件的紧密结合，这样使得只需要少量的代码便可以完成强大的功能，下面是一个例子 <a href="http://www.timisted.net/blog/archive/multiple-windows-with-core-data/" rel="nofollow">http://www.timisted.net/blog/archive/multiple-windows-with-core-data/</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin</title>
		<link>http://www.timisted.net/blog/archive/multiple-windows-with-core-data/comment-page-1/#comment-4306</link>
		<dc:creator>Kevin</dc:creator>
		<pubDate>Thu, 09 Sep 2010 13:34:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.timisted.net/blog/?p=3#comment-4306</guid>
		<description>Really great stuff. I&#039;ve been mentally struggling with how to mix multiple window documents with Core Data... Hillegass just wasn&#039;t helping me bring these things together as needed... and this tutorial was just the trick and perfectly explained. I get it now... Thanks!</description>
		<content:encoded><![CDATA[<p>Really great stuff. I&#8217;ve been mentally struggling with how to mix multiple window documents with Core Data&#8230; Hillegass just wasn&#8217;t helping me bring these things together as needed&#8230; and this tutorial was just the trick and perfectly explained. I get it now&#8230; Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Todd</title>
		<link>http://www.timisted.net/blog/archive/multiple-windows-with-core-data/comment-page-1/#comment-2905</link>
		<dc:creator>Todd</dc:creator>
		<pubDate>Thu, 15 Jul 2010 21:10:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.timisted.net/blog/?p=3#comment-2905</guid>
		<description>Thanks, Tim!!

Really great explanation.</description>
		<content:encoded><![CDATA[<p>Thanks, Tim!!</p>
<p>Really great explanation.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

