<?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: Implementing a Singleton in Objective-C / iOS</title>
	<atom:link href="http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/</link>
	<description>Mobile, iPhone and Game Programming Tutorials and Discussion</description>
	<lastBuildDate>Tue, 31 Jan 2012 08:10:19 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Alvin</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3384</link>
		<dc:creator>Alvin</dc:creator>
		<pubDate>Tue, 31 Jan 2012 08:10:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3384</guid>
		<description>For the thread-safe version you&#039;re using the variable &quot;singleton&quot; which should be &quot;sharedInstance&quot; instead right?</description>
		<content:encoded><![CDATA[<p>For the thread-safe version you&#8217;re using the variable &#8220;singleton&#8221; which should be &#8220;sharedInstance&#8221; instead right?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Osni Oliveira</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3324</link>
		<dc:creator>Osni Oliveira</dc:creator>
		<pubDate>Tue, 20 Dec 2011 15:49:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3324</guid>
		<description>Hi John,

    Thank you for your post, I found it to be very useful.
    Just a doubt here, your code for the allocWithZone overriding is:

// We don&#039;t want to allocate a new instance, so return the current one.
+ (id)allocWithZone:(NSZone*)zone {
    return [[self sharedInstance] retain];
}

    If sharedInstance is a static variable not bout to the class implementation (proof of that is you can declare it inside or outside the @implementation section), why use self? And, most important yet, why call retain on sharedInstance, since you also override the retain method to do nothing and just return self?</description>
		<content:encoded><![CDATA[<p>Hi John,</p>
<p>    Thank you for your post, I found it to be very useful.<br />
    Just a doubt here, your code for the allocWithZone overriding is:</p>
<p>// We don&#8217;t want to allocate a new instance, so return the current one.<br />
+ (id)allocWithZone:(NSZone*)zone {<br />
    return [[self sharedInstance] retain];<br />
}</p>
<p>    If sharedInstance is a static variable not bout to the class implementation (proof of that is you can declare it inside or outside the @implementation section), why use self? And, most important yet, why call retain on sharedInstance, since you also override the retain method to do nothing and just return self?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Van Du Tran</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3316</link>
		<dc:creator>Van Du Tran</dc:creator>
		<pubDate>Fri, 16 Dec 2011 19:41:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3316</guid>
		<description>Also, why in one case we have &quot;sharedInstance = [[super alloc] initWithZone()] and in the other case we have &quot;sharedInstance = [[SingletonClass alloc] init]</description>
		<content:encoded><![CDATA[<p>Also, why in one case we have &#8220;sharedInstance = [[super alloc] initWithZone()] and in the other case we have &#8220;sharedInstance = [[SingletonClass alloc] init]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Van Du Tran</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3315</link>
		<dc:creator>Van Du Tran</dc:creator>
		<pubDate>Fri, 16 Dec 2011 17:37:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3315</guid>
		<description>I think in the thread save section ther&#039;es an error:

01
02
03
04
05
06
07
08
09
10
11
12
+ (SingletonClass *)sharedInstance {
    if (nil != sharedInstance) {
        return sharedInstance;
    }
 
    static dispatch_once_t pred;        // Lock
    dispatch_once(&amp;pred, ^{             // This code is called at most once per app
        singleton = [[SingletonClass alloc] init];
    });
 
    return singleton;
}

it should be 

sharedInstance =  [[SingletonClass alloc] init];
and return sharedInstance;


Also, why is it in this case we do not call the initWithZone() but the regular init()?</description>
		<content:encoded><![CDATA[<p>I think in the thread save section ther&#8217;es an error:</p>
<p>01<br />
02<br />
03<br />
04<br />
05<br />
06<br />
07<br />
08<br />
09<br />
10<br />
11<br />
12<br />
+ (SingletonClass *)sharedInstance {<br />
    if (nil != sharedInstance) {<br />
        return sharedInstance;<br />
    }</p>
<p>    static dispatch_once_t pred;        // Lock<br />
    dispatch_once(&amp;pred, ^{             // This code is called at most once per app<br />
        singleton = [[SingletonClass alloc] init];<br />
    });</p>
<p>    return singleton;<br />
}</p>
<p>it should be </p>
<p>sharedInstance =  [[SingletonClass alloc] init];<br />
and return sharedInstance;</p>
<p>Also, why is it in this case we do not call the initWithZone() but the regular init()?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Wordsworth</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3247</link>
		<dc:creator>John Wordsworth</dc:creator>
		<pubDate>Thu, 03 Nov 2011 15:59:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3247</guid>
		<description>Hi Jared. Thanks for the comment.

I have always declared my static variables just under the @implementation tag and never run into any problems before. I believe that the only variables you can declare within the @implementation section of a class are static variables (unless you use @implementation{ variables } construct - which is a relatively new feature I think). I&#039;m fairly confident that declaring the static variable before or after the @implementation tag has exactly the same result and is simply down to style choice (I&#039;ve seen both in libraries).</description>
		<content:encoded><![CDATA[<p>Hi Jared. Thanks for the comment.</p>
<p>I have always declared my static variables just under the @implementation tag and never run into any problems before. I believe that the only variables you can declare within the @implementation section of a class are static variables (unless you use @implementation{ variables } construct &#8211; which is a relatively new feature I think). I&#8217;m fairly confident that declaring the static variable before or after the @implementation tag has exactly the same result and is simply down to style choice (I&#8217;ve seen both in libraries).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3244</link>
		<dc:creator>Jared</dc:creator>
		<pubDate>Tue, 01 Nov 2011 22:34:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3244</guid>
		<description>Shouldn&#039;t this line:

static SingletonClass *sharedInstance = nil;

Go before the @implementation tag? I don&#039;t think you can declare any variables inside it.?</description>
		<content:encoded><![CDATA[<p>Shouldn&#8217;t this line:</p>
<p>static SingletonClass *sharedInstance = nil;</p>
<p>Go before the @implementation tag? I don&#8217;t think you can declare any variables inside it.?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dustin Pfannenstiel</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3236</link>
		<dc:creator>Dustin Pfannenstiel</dc:creator>
		<pubDate>Mon, 24 Oct 2011 21:31:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3236</guid>
		<description>Never mind... problem existed between keyboard and chair.  Call super&#039;s allocWithZone.</description>
		<content:encoded><![CDATA[<p>Never mind&#8230; problem existed between keyboard and chair.  Call super&#8217;s allocWithZone.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dustin Pfannenstiel</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3235</link>
		<dc:creator>Dustin Pfannenstiel</dc:creator>
		<pubDate>Mon, 24 Oct 2011 21:29:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3235</guid>
		<description>Am I missing something?  How are you avoiding recursion hell...

You call the sharedInstance.  If it&#039;s nil allocWithZone.  Then in allocWithZone you return the sharedInstance, which requires calling sharedInstance.  At this point it should still be nil so call allocWithZone...

And repeat until insane.</description>
		<content:encoded><![CDATA[<p>Am I missing something?  How are you avoiding recursion hell&#8230;</p>
<p>You call the sharedInstance.  If it&#8217;s nil allocWithZone.  Then in allocWithZone you return the sharedInstance, which requires calling sharedInstance.  At this point it should still be nil so call allocWithZone&#8230;</p>
<p>And repeat until insane.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Implementing a thread-safe Singleton in iOS &#124; ampersand</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3135</link>
		<dc:creator>Implementing a thread-safe Singleton in iOS &#124; ampersand</dc:creator>
		<pubDate>Mon, 05 Sep 2011 15:08:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3135</guid>
		<description>[...] to the first result on my Google search, a singleton should be implemented as [...]</description>
		<content:encoded><![CDATA[<p>[...] to the first result on my Google search, a singleton should be implemented as [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Wordsworth</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3111</link>
		<dc:creator>John Wordsworth</dc:creator>
		<pubDate>Mon, 22 Aug 2011 14:45:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3111</guid>
		<description>Hi AjaxJava - thanks for dropping by and posting your comment. I hope my response helps to clear things up.

As we have overridden &lt;em&gt;allocWithZone:&lt;/em&gt; calling &lt;em&gt;[SingletonClass alloc]&lt;/em&gt; will in turn call allocWithZone:, which simply returns the one singleton copy of this object (by calling the +sharedInstance method). If the static object does not exist already, then it will be created during the alloc call and a reference to it returned. Either way, you are still providing access to the one and only singleton object that exists in memory. Therefore, calling &lt;em&gt;[[SingletonClass alloc] init]&lt;/em&gt; will return the one single copy of this class (creating it if necessary) and then call the &lt;em&gt;init&lt;/em&gt; method on that instance. It is the overridden allocWithZone method that ensures that another copy of this object is never created in memory.

If you are in a situation where you need to have a single copy of this class that is controlled and accessed by using &lt;em&gt;[SingletonClass sharedInstance]&lt;/em&gt; but would also like to be able to create other copies of this class for other uses, then you can remove the methods &lt;em&gt;allocWithZone:, copyWithZone, retain, retainCount, release, autorelease&lt;/em&gt; from the above code listing (basically, remove all methods except sharedInstance and init). This removes the restraint that only one copy of this class may ever exist, so only the one created by the sharedInstance method will be managed for you - you will have to memory manage all other copies of this class that you make yourself. Personally, i would err away from doing this, as I prefer to think that a class is either a Singleton or not (and not some strange hybrid), but the choice is yours!</description>
		<content:encoded><![CDATA[<p>Hi AjaxJava &#8211; thanks for dropping by and posting your comment. I hope my response helps to clear things up.</p>
<p>As we have overridden <em>allocWithZone:</em> calling <em>[SingletonClass alloc]</em> will in turn call allocWithZone:, which simply returns the one singleton copy of this object (by calling the +sharedInstance method). If the static object does not exist already, then it will be created during the alloc call and a reference to it returned. Either way, you are still providing access to the one and only singleton object that exists in memory. Therefore, calling <em>[[SingletonClass alloc] init]</em> will return the one single copy of this class (creating it if necessary) and then call the <em>init</em> method on that instance. It is the overridden allocWithZone method that ensures that another copy of this object is never created in memory.</p>
<p>If you are in a situation where you need to have a single copy of this class that is controlled and accessed by using <em>[SingletonClass sharedInstance]</em> but would also like to be able to create other copies of this class for other uses, then you can remove the methods <em>allocWithZone:, copyWithZone, retain, retainCount, release, autorelease</em> from the above code listing (basically, remove all methods except sharedInstance and init). This removes the restraint that only one copy of this class may ever exist, so only the one created by the sharedInstance method will be managed for you &#8211; you will have to memory manage all other copies of this class that you make yourself. Personally, i would err away from doing this, as I prefer to think that a class is either a Singleton or not (and not some strange hybrid), but the choice is yours!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ajaxjava</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3110</link>
		<dc:creator>Ajaxjava</dc:creator>
		<pubDate>Mon, 22 Aug 2011 04:09:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3110</guid>
		<description>Can this [[SingletonClass alloc] init] still be called to create a new object? If yes, how to guarantee there is only one object in the memory?</description>
		<content:encoded><![CDATA[<p>Can this [[SingletonClass alloc] init] still be called to create a new object? If yes, how to guarantee there is only one object in the memory?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Wordsworth</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3083</link>
		<dc:creator>John Wordsworth</dc:creator>
		<pubDate>Fri, 05 Aug 2011 00:23:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3083</guid>
		<description>Hi Claudio, no question is stupid when it comes to programming! Some things might be easier to grasp than others, but it&#039;s actually all pretty complicated stuff when you take a step back and consider it.

With regards to your question, you don&#039;t really need to treat your Singleton any differently to any other object. I&#039;ve updated the example above to include a template &#039;init&#039; method where you might want to include your normal initialisation-type code for this object. The init method will only be called once, and that will be just before the first time you get your hands on the singleton (the first time you call [SingletonClass sharedInstance]).

The only major caveat, is that you want to err away from init method that take parameters. As you&#039;re not expected to care when / where your Singleton is initialised (it could be called anywhere in your code) it&#039;s best to veer away from having any &#039;initWith&#039; methods. It&#039;s preferable to have a basic init method that sets up any required sub-objects and then you can configure those objects with additional instance methods on the singleton.

Hope this helps, if you have any further problems, or this isn&#039;t very clear - please don&#039;t hesitate to drop me another message.</description>
		<content:encoded><![CDATA[<p>Hi Claudio, no question is stupid when it comes to programming! Some things might be easier to grasp than others, but it&#8217;s actually all pretty complicated stuff when you take a step back and consider it.</p>
<p>With regards to your question, you don&#8217;t really need to treat your Singleton any differently to any other object. I&#8217;ve updated the example above to include a template &#8216;init&#8217; method where you might want to include your normal initialisation-type code for this object. The init method will only be called once, and that will be just before the first time you get your hands on the singleton (the first time you call [SingletonClass sharedInstance]).</p>
<p>The only major caveat, is that you want to err away from init method that take parameters. As you&#8217;re not expected to care when / where your Singleton is initialised (it could be called anywhere in your code) it&#8217;s best to veer away from having any &#8216;initWith&#8217; methods. It&#8217;s preferable to have a basic init method that sets up any required sub-objects and then you can configure those objects with additional instance methods on the singleton.</p>
<p>Hope this helps, if you have any further problems, or this isn&#8217;t very clear &#8211; please don&#8217;t hesitate to drop me another message.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Claudio</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3080</link>
		<dc:creator>Claudio</dc:creator>
		<pubDate>Thu, 04 Aug 2011 15:01:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3080</guid>
		<description>Hey John,

Great stuff...  I was wondering where I would initialize other objects within my singleton?  Would you do it after the allocation of the shared instance or use  &quot;+initialize&quot; ?  Not sure what the &quot;best practice&quot; is...
 
    if (sharedInstance == nil) {
        sharedInstance = [[super allocWithZone:NULL] init];
        /* WOULD I DO IT HERE */
    }

I&#039;m still a n00bie with Objective C so I apologize if the question is stupid.

Thanks,
Claudio</description>
		<content:encoded><![CDATA[<p>Hey John,</p>
<p>Great stuff&#8230;  I was wondering where I would initialize other objects within my singleton?  Would you do it after the allocation of the shared instance or use  &#8220;+initialize&#8221; ?  Not sure what the &#8220;best practice&#8221; is&#8230;</p>
<p>    if (sharedInstance == nil) {<br />
        sharedInstance = [[super allocWithZone:NULL] init];<br />
        /* WOULD I DO IT HERE */<br />
    }</p>
<p>I&#8217;m still a n00bie with Objective C so I apologize if the question is stupid.</p>
<p>Thanks,<br />
Claudio</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Wordsworth</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3066</link>
		<dc:creator>John Wordsworth</dc:creator>
		<pubDate>Wed, 20 Jul 2011 14:22:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3066</guid>
		<description>Hi Van Du, 

I could be wrong, but I&#039;m pretty sure that copyWithZone should be an instance method (-) and not static (+). The method would normally be used to return a new instance that is a copy of the object that you call this method on. We simply return &#039;self&#039; from the shared instance (you would call this [[SingletonObject sharedInstance] copyWithZone:zone]) as we don&#039;t allow for more than one instance of the singleton to exist. See the NSCopying protocol for further details.

Thanks for the comment, I&#039;m still learning a lot of this as I go - so it&#039;s always interesting to talk over certain points.</description>
		<content:encoded><![CDATA[<p>Hi Van Du, </p>
<p>I could be wrong, but I&#8217;m pretty sure that copyWithZone should be an instance method (-) and not static (+). The method would normally be used to return a new instance that is a copy of the object that you call this method on. We simply return &#8216;self&#8217; from the shared instance (you would call this [[SingletonObject sharedInstance] copyWithZone:zone]) as we don&#8217;t allow for more than one instance of the singleton to exist. See the NSCopying protocol for further details.</p>
<p>Thanks for the comment, I&#8217;m still learning a lot of this as I go &#8211; so it&#8217;s always interesting to talk over certain points.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Wordsworth</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3060</link>
		<dc:creator>John Wordsworth</dc:creator>
		<pubDate>Mon, 11 Jul 2011 17:40:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3060</guid>
		<description>Hi Scott, the singleton will only be released when the app closes. Otherwise - the Singleton model is designed to kick around for the lifetime of your application. You could, of course, release elements that exist within your Singleton if you want to clear-up some memory and you&#039;re storing large objects in your Singleton object!</description>
		<content:encoded><![CDATA[<p>Hi Scott, the singleton will only be released when the app closes. Otherwise &#8211; the Singleton model is designed to kick around for the lifetime of your application. You could, of course, release elements that exist within your Singleton if you want to clear-up some memory and you&#8217;re storing large objects in your Singleton object!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: scott</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3053</link>
		<dc:creator>scott</dc:creator>
		<pubDate>Fri, 27 May 2011 23:48:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3053</guid>
		<description>thank you for writing out the code. this really helps.  so does the singleton ever get released eventually?</description>
		<content:encoded><![CDATA[<p>thank you for writing out the code. this really helps.  so does the singleton ever get released eventually?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Van Du</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3050</link>
		<dc:creator>Van Du</dc:creator>
		<pubDate>Mon, 16 May 2011 23:11:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3050</guid>
		<description>Hi,

I think this is wrong:

// Equally, we don&#039;t want to generate multiple copies of the singleton.
- (id)copyWithZone:(NSZone *)zone {
    return self;
}

it should be:

+ (id)copyWithZone:(NSZone *)zone {
 return self;
};


However, will return self still works or do we need to call [self sharedInstance]?

Thanks,</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I think this is wrong:</p>
<p>// Equally, we don&#8217;t want to generate multiple copies of the singleton.<br />
- (id)copyWithZone:(NSZone *)zone {<br />
    return self;<br />
}</p>
<p>it should be:</p>
<p>+ (id)copyWithZone:(NSZone *)zone {<br />
 return self;<br />
};</p>
<p>However, will return self still works or do we need to call [self sharedInstance]?</p>
<p>Thanks,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Using Singletons for iPhone iOS 4 Global Variables &#171; Nick Napier</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3048</link>
		<dc:creator>Using Singletons for iPhone iOS 4 Global Variables &#171; Nick Napier</dc:creator>
		<pubDate>Fri, 13 May 2011 13:25:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3048</guid>
		<description>[...] http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comm... [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comm.." rel="nofollow">http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comm..</a>. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3047</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Fri, 13 May 2011 12:33:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3047</guid>
		<description>Hello Again,

I actually figured things out myself so no need to reply. This is what I ended up doing:

I added the following under the *.h:

      NSString *general;

With a method as follows:

      @property (nonatomic, copy) NSString *general;

I then added the following under the *.m:

      @synthesize general;

Then I was able to get and set the saved global information by adding the following under the other object:

// set the value of the global &quot;general&quot; variable I created in the singleton class

-(IBAction) setValue:(id)sender { 
        [[GlobalsObject sharedInstance] setGeneral:@&quot;test&quot;];    
}

// get the value of the global &quot;general&quot; variable that was set in the &quot;setValue&quot; action

-(IBAction) setTextValue:(id)sender {     
        barcode.text = [[GlobalsObject sharedInstance] general];
}

Thank you so much for posting this amazing tutorial. I am a brand new programmer and without this I would have never been able to complete my project. John Wordsworth, you are the man!

Nick</description>
		<content:encoded><![CDATA[<p>Hello Again,</p>
<p>I actually figured things out myself so no need to reply. This is what I ended up doing:</p>
<p>I added the following under the *.h:</p>
<p>      NSString *general;</p>
<p>With a method as follows:</p>
<p>      @property (nonatomic, copy) NSString *general;</p>
<p>I then added the following under the *.m:</p>
<p>      @synthesize general;</p>
<p>Then I was able to get and set the saved global information by adding the following under the other object:</p>
<p>// set the value of the global &#8220;general&#8221; variable I created in the singleton class</p>
<p>-(IBAction) setValue:(id)sender {<br />
        [[GlobalsObject sharedInstance] setGeneral:@&#8221;test&#8221;];<br />
}</p>
<p>// get the value of the global &#8220;general&#8221; variable that was set in the &#8220;setValue&#8221; action</p>
<p>-(IBAction) setTextValue:(id)sender {<br />
        barcode.text = [[GlobalsObject sharedInstance] general];<br />
}</p>
<p>Thank you so much for posting this amazing tutorial. I am a brand new programmer and without this I would have never been able to complete my project. John Wordsworth, you are the man!</p>
<p>Nick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick</title>
		<link>http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/comment-page-1/#comment-3046</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Thu, 12 May 2011 16:58:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.johnwordsworth.com/?p=73#comment-3046</guid>
		<description>Hello,

I&#039;m sorry for the trouble but I&#039;m a bit confused about the final use lines that you provided:

[sharedSingleton callAMethod];

With the &quot;callAMethod&quot; part, do we create a method in the singleton and set the data to it or am I losing something? I&#039;m very new to this so I apologize for not being able to get my point across well. Thanks in advance.

Nick</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I&#8217;m sorry for the trouble but I&#8217;m a bit confused about the final use lines that you provided:</p>
<p>[sharedSingleton callAMethod];</p>
<p>With the &#8220;callAMethod&#8221; part, do we create a method in the singleton and set the data to it or am I losing something? I&#8217;m very new to this so I apologize for not being able to get my point across well. Thanks in advance.</p>
<p>Nick</p>
]]></content:encoded>
	</item>
</channel>
</rss>

