<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Make Better Things</title>
	<atom:link href="http://www.makebetterthings.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.makebetterthings.com</link>
	<description>I like to make better things.</description>
	<lastBuildDate>Wed, 16 May 2012 14:04:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Distribute Enterprise applications Over The Air (OTA)</title>
		<link>http://www.makebetterthings.com/iphone/distribute-enterprise-applications-over-the-air-ota/</link>
		<comments>http://www.makebetterthings.com/iphone/distribute-enterprise-applications-over-the-air-ota/#comments</comments>
		<pubDate>Wed, 16 May 2012 11:41:59 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Enterprise apps]]></category>
		<category><![CDATA[OTA]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/?p=314</guid>
		<description><![CDATA[iOS supports over-the-air installation of enterprise apps, letting you distribute in-house software to your users without using iTunes or iPhone Configuration Utility. Here are the steps by which you can create OTA distribution for your Enterprise apps. Step 1: Archive your project as usual and open Organizer. Step 2: Select the file you want to [...]]]></description>
			<content:encoded><![CDATA[<p>iOS supports over-the-air installation of enterprise apps, letting you distribute in-house software to your users without using iTunes or iPhone Configuration Utility.</p>
<p>Here are the steps by which you can create OTA distribution for your Enterprise apps.</p>
<p>Step 1: Archive your project as usual and open Organizer.</p>
<p>Step 2: Select the file you want to distribute and press the Share button.</p>
<p><a href="http://www.makebetterthings.com/iphone/distribute-enterprise-applications-over-the-air-ota/attachment/screen-shot-2012-05-16-at-4-31-04-pm/" rel="attachment wp-att-315"><img class="alignnone size-large wp-image-315" title="Screen shot 2012-05-16 at 4.31.04 PM" src="http://www.makebetterthings.com/wp-content/uploads/2012/05/Screen-shot-2012-05-16-at-4.31.04-PM-400x144.png" alt="" width="400" height="144" /></a></p>
<p>Step 3: Select &#8220;iOS App Store Package (.ipa) and press next.</p>
<p><a href="http://www.makebetterthings.com/iphone/distribute-enterprise-applications-over-the-air-ota/attachment/screen-shot-2012-05-16-at-3-55-36-pm/" rel="attachment wp-att-316"><img class="alignnone size-large wp-image-316" title="Screen shot 2012-05-16 at 3.55.36 PM" src="http://www.makebetterthings.com/wp-content/uploads/2012/05/Screen-shot-2012-05-16-at-3.55.36-PM-400x272.png" alt="" width="400" height="272" /></a></p>
<p>Step 4: A new window will which will ask you to enter the name of the ipa file. There is a check box at the bottom of the screen &#8220;Save for Enterprise Distribution&#8221;, select this check box.</p>
<p><a href="http://www.makebetterthings.com/iphone/distribute-enterprise-applications-over-the-air-ota/attachment/screen-shot-2012-05-16-at-4-33-06-pm/" rel="attachment wp-att-317"><img class="alignnone size-large wp-image-317" title="Screen shot 2012-05-16 at 4.33.06 PM" src="http://www.makebetterthings.com/wp-content/uploads/2012/05/Screen-shot-2012-05-16-at-4.33.06-PM-400x208.png" alt="" width="400" height="208" /></a></p>
<p>Step 5: The window will expand to look something like this.</p>
<p><a href="http://www.makebetterthings.com/iphone/distribute-enterprise-applications-over-the-air-ota/attachment/screen-shot-2012-05-16-at-4-44-45-pm/" rel="attachment wp-att-318"><img class="alignnone size-large wp-image-318" title="Screen shot 2012-05-16 at 4.44.45 PM" src="http://www.makebetterthings.com/wp-content/uploads/2012/05/Screen-shot-2012-05-16-at-4.44.45-PM-400x208.png" alt="" width="400" height="208" /></a></p>
<p>It will ask you few information on where you want to host the file, its icons and title.</p>
<p>Make sure you enter the application URL to the complete url of the file you would host on your server. Then enter title, subtitle, large icon url (512&#215;512) and small icon url (57&#215;57). Once you select the &#8220;ok&#8221; a .ipa file and .plist file will save in your select folder.</p>
<p>Step 6: Now we need to create a html file which will have the link of the plist file. Here is the sample file -</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;Sushi App&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;itms-services://?action=download-manifest&amp;url=http://122.160.153.125/sushi_ota_16_05_2012.plist&quot;&gt; Tap Here to Install the Application&lt;/a&gt;
  &lt;/li&gt;
  &lt;/ul&gt;
&lt;/body&gt; &lt;/html&gt;
</pre>
<p>Notice the url in form &#8211; itms-services://?action=download-manifest&amp;url=http://122.160.153.125/sushi_ota_16_05_2012.ipa<br />
The above is just a sample html which have only the link, you can create more good looking files but just be careful with the link.</p>
<p>Step 7: Now upload .ipa file, .plist file and .html file on the webserver (which you mentioned while saving the ipa file).</p>
<p>Step 8: Open the html file in safari and tap the link to install the app on your device.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/iphone/distribute-enterprise-applications-over-the-air-ota/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is the difference among nil, NULL, Nil in Objective-C?</title>
		<link>http://www.makebetterthings.com/objective-c/what-is-the-difference-among-nil-null-nil-in-objective-c/</link>
		<comments>http://www.makebetterthings.com/objective-c/what-is-the-difference-among-nil-null-nil-in-objective-c/#comments</comments>
		<pubDate>Tue, 01 May 2012 07:42:55 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[nil]]></category>
		<category><![CDATA[NULL]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/?p=311</guid>
		<description><![CDATA[They are all zeros, the difference lies in their types -&#62; NULL is a generic pointer value ((void*)0, to be specific). It points to 0&#215;0. -&#62; nil is an id. So its points to a non-existent objective-c object -&#62; Nil is a non-existent objective-c class -&#62; [NSNull null] is an object that&#8217;s meant to stand [...]]]></description>
			<content:encoded><![CDATA[<p>They are all zeros, the difference lies in their types</p>
<p>-&gt; NULL is a generic pointer value ((void*)0, to be specific). It points to 0&#215;0.<br />
-&gt; nil is an id. So its points to a non-existent objective-c object<br />
-&gt; Nil is a non-existent objective-c class<br />
-&gt; [NSNull null] is an object that&#8217;s meant to stand in for nil in situations where nil isn&#8217;t allowed. For example, you can&#8217;t have a nil value in an NSArray. So if you need to represent a &#8220;nil&#8221;, you can use [NSNull null]</p>
<p>Also there is no &#8216;null&#8217; in the objective c its &#8216;NULL&#8217; not &#8216;null&#8217;. &#8216;null&#8217; exist in Java or in C# not in Objective-C</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/objective-c/what-is-the-difference-among-nil-null-nil-in-objective-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Variable number of arguments in Objective-C methods</title>
		<link>http://www.makebetterthings.com/iphone/variable-number-of-arguments-in-objective-c-methods/</link>
		<comments>http://www.makebetterthings.com/iphone/variable-number-of-arguments-in-objective-c-methods/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 08:43:52 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[variable argument methods]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/?p=307</guid>
		<description><![CDATA[Ever wondered how the NSString&#8217;s +stringWithFormat: method work? How you can pass endless arguments in it? Well methods that take variable arguments are known as variadic methods. Here is an example of such a method Declare variable argument function in your .h file as below Here is the definition in .m file &#8211;]]></description>
			<content:encoded><![CDATA[<p>Ever wondered how the NSString&#8217;s +stringWithFormat: method work? How you can pass endless arguments in it?</p>
<p>Well methods that take variable arguments are known as <strong>variadic</strong> methods.</p>
<p>Here is an example of such a method</p>
<p>Declare variable argument function in your .h file as below </p>
<pre class="brush: objc; title: ; notranslate">
- (void) appendObjects:(id) firstObject, ...; // This method takes a nil-terminated list of objects.
</pre>
<p>Here is the definition in .m file &#8211; </p>
<pre class="brush: objc; title: ; notranslate">
- (void) appendObjects:(id) firstObject, ...
{
     id eachObject;
     va_list argumentList;
     if (firstObject) // The first argument isn't part of the varargs list,
     {
           [self addObject: firstObject];// so we'll handle it separately.
           va_start(argumentList, firstObject); // Start scanning for arguments after firstObject.
           while (eachObject = va_arg(argumentList, id)) // As many times as we can get an argument of type &quot;id&quot;
           {
               [self addObject: eachObject]; // that isn't nil, add it to self's contents.
           }
           va_end(argumentList);

     }

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/iphone/variable-number-of-arguments-in-objective-c-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iOS development learning resources</title>
		<link>http://www.makebetterthings.com/iphone/ios-development-learning-resources/</link>
		<comments>http://www.makebetterthings.com/iphone/ios-development-learning-resources/#comments</comments>
		<pubDate>Sun, 18 Mar 2012 06:05:01 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[learning resources]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/?p=298</guid>
		<description><![CDATA[Here is a good compilation of links useful in learning iOS development 1) Blogs on iPhone development http://www.cimgf.com/ http://mycodeteacher.com/ http://iphonedevelopment.blogspot.com/ http://iphoneincubator.com/blog/ http://iphone.zcentric.com/ http://iphoneproghelp.blogspot.com/ (Programming Tutorial) http://icodeblog.com/ (Programming Tutorial) http://idevrecipes.com/ 2) iPhone Source Code http://www.theiphonedev.com/SourceCode/tabid/143/Default.aspx 3) Community http://www.iphonekicks.com/ https://devforums.apple.com/ http://iphonedevsdk.com/ 4) News http://mobileorchard.com/ http://theappleblog.com/ 5) Jail breaking/Hacking http://theiphoneproject.org/ 6) Open source libraries and Applications http://www.codingventures.com/2008/12/useful-open-source-libraries-for-iphone-development/#more-43 http://www.sourcemac.com/ [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a good compilation of links useful in learning iOS development</p>
<p><strong>1) Blogs on iPhone development</strong></p>
<p>http://www.cimgf.com/</p>
<p>http://mycodeteacher.com/</p>
<p>http://iphonedevelopment.blogspot.com/</p>
<p>http://iphoneincubator.com/blog/</p>
<p>http://iphone.zcentric.com/</p>
<p>http://iphoneproghelp.blogspot.com/ (Programming Tutorial)<br />
http://icodeblog.com/ (Programming Tutorial)</p>
<p>http://idevrecipes.com/</p>
<p><strong>2) iPhone Source Code</strong></p>
<p>http://www.theiphonedev.com/SourceCode/tabid/143/Default.aspx</p>
<p><strong>3) Community</strong></p>
<p>http://www.iphonekicks.com/</p>
<p>https://devforums.apple.com/</p>
<p>http://iphonedevsdk.com/</p>
<p><strong>4) News</strong></p>
<p>http://mobileorchard.com/</p>
<p>http://theappleblog.com/</p>
<p><strong>5) Jail breaking/Hacking</strong></p>
<p>http://theiphoneproject.org/</p>
<p><strong>6) Open source libraries and Applications</strong></p>
<p>http://www.codingventures.com/2008/12/useful-open-source-libraries-for-iphone-development/#more-43</p>
<p>http://www.sourcemac.com/</p>
<p>http://www.codeplex.com/</p>
<p>Face Detection: http://niw.at/articles/2009/03/14/using-opencv-on-iphone/en<br />
Bar Code: Is there a barcode recognition framework for iOS?<br />
Rating: http://github.com/eisernWolf/TouchCustoms</p>
<p>http://github.com/erica/iphone-3.0-cookbook-</p>
<p>Is there a gallery of reusable iPhone components on the web?</p>
<p>http://mattgemmell.com/source</p>
<p>http://www.cocoacontrols.com/</p>
<p>http://open.iphonedev.com/</p>
<p>http://www.opensourceresources.org/</p>
<p>http://www.raywenderlich.com/tag/sample-code</p>
<p>Three 20: http://github.com/facebook/three20<br />
Tapku Library: http://github.com/devinross/tapkulibrary</p>
<p><strong>7) Topic-wise</strong><br />
App Store: https://developer.apple.com/appstore/resources/approval/guidelines.html<br />
GIF Support: http://stackoverflow.com/questions/1379818/how-can-i-make-an-animated-gif-with-the-iphone-sdk<br />
In App Purchase: http://www.sixtemia.com/journal/2009/08/12/using-store-kit-framework/<br />
IP Address: http://www.iphonedevsdk.com/forum/iphone-sdk-development/5293-get-current-ip-address.html<br />
Page Curl Animation: What iPhone OS APIs could I use to implement a transition animation similar to the iBook page flip transition?<br />
TTF Font http://github.com/zynga/FontLabel<br />
Rotate Label: http://iphonedevelopment.blogspot.com/2009/12/better-two-finger-rotate-gesture.html<br />
Speech Recognition &#8211; 1: http://cmusphinx.sourceforge.net/<br />
Speech Recognition &#8211; 2: http://www.politepix.com/openears/<br />
Operation and Thread: http://www.cimgf.com/2008/02/16/cocoa-tutorial-nsoperation-and-nsoperationqueue/<br />
Web service: http://icodeblog.com/2008/11/03/iphone-programming-tutorial-intro-to-soap-web-services/<br />
Code Analyzer: http://clang.llvm.org/StaticAnalysis.html<br />
Game Center: http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-game-center-achievements-and-leaderboards-part-1/<br />
SMS Chat: https://github.com/acani/AcaniChat<br />
Rotating Knob: https://github.com/hollance/MHRotaryKnob</p>
<p><strong>8 ) Game Development with Cocos2D</strong></p>
<p>http://code.google.com/p/cocos2d-iphone/</p>
<p>http://blog.sapusmedia.com/search/label/cocos2d</p>
<p>http://iphonesdkdev.blogspot.com/2009/01/xcode-template-for-cocos2d.html</p>
<p>http://monoclestudios.com/cocos2d_whitepaper.ht</p>
<p>http://lethain.com/entry/2008/oct/03/notes-on-cocos2d-iphone-development/</p>
<p>http://lethain.com/entry/2008/oct/20/touch-detection-in-cocos2d-iphone/</p>
<p>Open GL: http://web.me.com/smaurice/AppleCoder/iPhone_OpenGL/Archive.html</p>
<p><strong>9) Drawing Charts and Graphs</strong></p>
<p>http://code.google.com/p/core-plot/</p>
<p>http://code.google.com/p/s7graphview/</p>
<p>http://github.com/duivesteyn-enterprises/deSimpleChart</p>
<p>http://www.rgraph.net/ (Will work on UIWebView only)<br />
http://sebkade.wordpress.com/2010/05/06/basic-graph-class-for-iphone/ (a blog where demo is given to create a graph)</p>
<p><strong>10) Map Kit</strong></p>
<p>http://github.com/kishikawakatsumi/MapKit-Route-Directions</p>
<p>http://www.iphonedevsdk.com/forum/iphone-sdk-development/8100-opening-maps-app-given-route-direction.html</p>
<p>http://spitzkoff.com/craig/?p=65</p>
<p><strong>11) Audio Streaming</strong></p>
<p>http://code.google.com/p/indie1031/</p>
<p>http://cocoawithlove.com/2010/03/streaming-mp3aac-audio-again.html</p>
<p>http://code.google.com/p/audiostreamer-meta/</p>
<p>http://github.com/DigitalDJ/AudioStreamer</p>
<p>http://lists.apple.com/archives/coreaudio-api/2009/Jan//msg00143.html</p>
<p>https://bitbucket.org/brentsimmons/ngmovieplayer/ (It&#8217;s a code for streaming video using     AVPlayer class. Same code could be applied for streaming audio as well by minor modification)</p>
<p><strong>12) Twitter</strong></p>
<p>http://code.google.com/p/tweetphoto-api-objective-c/</p>
<p>http://tweetphoto-api-objective-c.googlecode.com/files/TweetPhoto.zip</p>
<p><strong>13) Scroll View</strong></p>
<p>http://github.com/andreyvit/ScrollingMadness</p>
<p><strong>14) SQLite</strong></p>
<p>http://code.google.com/p/sqlitepersistentobjects/</p>
<p>http://www.slideshare.net/360conferences/using-sqlite</p>
<p><strong>15) Video</strong><br />
How to play YouTube Movie on an iPhone Application when tapped on UITableViewCell?</p>
<p>http://www.iphonedevsdk.com/forum/iphone-sdk-development/41322-convert-image-sequences-video.html</p>
<p><strong>16) SCM</strong></p>
<p>http://iphonedevelopment.blogspot.com/2009/03/version-control-is-your-friend.html</p>
<p>http://developer.apple.com/tools/subversionxcode.html</p>
<p>Which SCM system for Xcode?</p>
<p>http://www.covertapps.com/development/6-setting-up-your-xcode-scm-repositories</p>
<p><strong>17) Testing: Functional Testing</strong></p>
<p>http://www.gorillalogic.com/fonemonkey</p>
<p>Unit Testing:<br />
i) http://code.google.com/p/google-toolbox-for-mac/<br />
ii)http://developer.apple.com/tools/unittest.html<br />
Automated Testing:<br />
i) http://cocoawithlove.com/2008/11/automated-user-interface-testing-on.html<br />
ii)http://code.google.com/p/uispec/<br />
iii) http://answers.oreilly.com/topic/1646-how-to-use-uiautomation-to-create-iphone-ui-tests/</p>
<p><strong>18) Push Notification</strong></p>
<p>http://blog.boxedice.com/2009/07/10/how-to-build-an-apple-push-notification-provider-server-tutorial/</p>
<p>http://urbanairship.com/</p>
<p><strong>19) Core Data Tutorial for Beginners</strong></p>
<p>http://www.raywenderlich.com/934/core-data-tutorial-getting-started</p>
<p><strong>20) VOIP</strong></p>
<p>http://code.google.com/p/idoubs/</p>
<p>http://code.google.com/p/siphon/</p>
<p>http://github.com/pzion/miumiu</p>
<p>http://www.linphone.org/eng/download/git.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/iphone/ios-development-learning-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.gitignore for iOS projects</title>
		<link>http://www.makebetterthings.com/iphone/gitignore-for-ios-projects/</link>
		<comments>http://www.makebetterthings.com/iphone/gitignore-for-ios-projects/#comments</comments>
		<pubDate>Sun, 04 Mar 2012 05:47:17 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[.gitignore]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/?p=293</guid>
		<description><![CDATA[You just started to use git with your iOS projects and wants to know which files you should&#8217;t track for version control? Here is a list of files you should&#8217;t track which using git &#8211; You just need to create a .gitignore file in your project directory and put the above content in that file.]]></description>
			<content:encoded><![CDATA[<p>You just started to use git with your iOS projects and wants to know which files you should&#8217;t track for version control? Here is a list of files you should&#8217;t track which using git &#8211; </p>
<pre class="brush: objc; title: ; notranslate">
# Exclude the build directory
build/*

# Exclude temp nibs and swap files
*~.nib
*.swp

# Exclude OS X folder attributes
.DS_Store

# Exclude user-specific XCode 3 and 4 files
*.mode1
*.mode1v3
*.mode2v3
*.perspective
*.perspectivev3
*.pbxuser
*.xcworkspace
xcuserdata
</pre>
<p>You just need to create a .gitignore file in your project directory and put the above content in that file. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/iphone/gitignore-for-ios-projects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xcode 4.2 documentation offline install</title>
		<link>http://www.makebetterthings.com/iphone/xcode-4-2-documentation-offline-install/</link>
		<comments>http://www.makebetterthings.com/iphone/xcode-4-2-documentation-offline-install/#comments</comments>
		<pubDate>Sun, 25 Dec 2011 16:51:25 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[xcode]]></category>
		<category><![CDATA[Xcode 4.2]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/?p=276</guid>
		<description><![CDATA[If you have installed the new Xcode 4.2 (only a 1.6 GB file instead of the former 4GB file), you will notice that documentation does not work properly, actually people have been complaining about it and the solution was to download the documentation from inside Xcode preferences. But if you are a team of iOS [...]]]></description>
			<content:encoded><![CDATA[<p>If you have installed the new Xcode 4.2 (only a 1.6 GB file instead of the former 4GB file), you will notice that documentation does not work properly, actually people have been complaining about it and the solution was to download the documentation from inside Xcode preferences.</p>
<p>But if you are a team of iOS developers and want to download the documentation only once and install it on many machines running Xcode?<br />
Here you are the steps:<br />
1. Download the documentation from Xcode from any machine.<br />
2. Go the download installation (See Figure Below)</p>
<p><a href="http://www.makebetterthings.com/iphone/xcode-4-2-documentation-offline-install/attachment/doc_offline_install-2/" rel="attachment wp-att-289"><img title="doc_offline_install" src="http://www.makebetterthings.com/wp-content/uploads/2011/12/doc_offline_install1-400x280.png" alt="" width="400" height="280" /></a><br />
3. Copy the &#8220;documentation set&#8221; files (it is actually packages with a lot of file so it is recommend to zip them).<br />
4. Move them to the same location where you installed Xcode on the other machines<br />
5. Restart Xcode.<br />
6. Done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/iphone/xcode-4-2-documentation-offline-install/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check iOS version and write conditional code</title>
		<link>http://www.makebetterthings.com/iphone/check-ios-version-and-write-conditional-code/</link>
		<comments>http://www.makebetterthings.com/iphone/check-ios-version-and-write-conditional-code/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 14:10:52 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[UIDevice]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/?p=267</guid>
		<description><![CDATA[I strongly recommend not to use iOS version numbers to write conditional code. There is usually a more reliable method of checking whether a particular feature available or not. But if you are in a deadly situation and hardly needed the version number then you can get iOS version number by UIDevice class. Here is [...]]]></description>
			<content:encoded><![CDATA[<p>I strongly recommend not to use iOS version numbers to write conditional code. There is usually a more reliable method of checking whether a particular feature available or not. But if you are in a deadly situation and hardly needed the version number then you can get iOS version number by UIDevice class. Here is the real code &#8211; </p>
<pre class="brush: objc; title: ; notranslate">

NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
</pre>
<p>Here is how you can use this to write conditional code &#8211; </p>
<pre class="brush: objc; title: ; notranslate">

// A system version of 3.1 or greater is required to use CADisplayLink. The NSTimer
// class is used as fallback when it isn't available.
NSString *reqSysVer = @&quot;3.1&quot;;
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
    displayLinkSupported = TRUE;
</pre>
<p>Above code works great but writing this condition is real pain every time. The solution of this is Macros. We can use Macros in objective c and reduce the line of code in above code. </p>
<p>Here is real code using Macros &#8211; </p>
<pre class="brush: objc; title: ; notranslate">
/*
 *  System Versioning Preprocessor Macros
 */ 

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
</pre>
<p>And how we can use these Macros to write conditional code &#8211; </p>
<pre class="brush: objc; title: ; notranslate">

/*
 *  Usage
 */ 

if (SYSTEM_VERSION_LESS_THAN(@&quot;4.0&quot;)) {
    ...
}

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@&quot;3.1.1&quot;)) {
    ...
}
</pre>
<p>Hope these Macros will save someone&#8217;s time. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/iphone/check-ios-version-and-write-conditional-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Recipe for Programming Success</title>
		<link>http://www.makebetterthings.com/uncategorized/recipe-for-programming-success/</link>
		<comments>http://www.makebetterthings.com/uncategorized/recipe-for-programming-success/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 18:23:02 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[success]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/?p=262</guid>
		<description><![CDATA[Here&#8217;s my recipe for programming success: • Get interested in programming, and do some because it is fun. • Talk to other programmers; read other programs. This is more important than any book or training course. • Program. The best kind of learning is learning by doing. To put it more technically, &#8220;the maximal level [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s my recipe for programming success:</p>
<p>• Get interested in programming, and do some because it is fun.</p>
<p>• Talk to other programmers; read other programs. This is more important than any book or training course.</p>
<p>• Program. The best kind of learning is learning by doing. To put it more technically, &#8220;the maximal level of performance for individuals in a given domain is not attained automatically as a function of extended experience, but the level of performance can be increased even by highly experienced individuals as a result of deliberate efforts to improve.&#8221; and &#8220;the most effective learning requires a well-defined task with an appropriate difficulty level for the particular individual, informative feedback, and opportunities for repetition and corrections of errors.&#8221;</p>
<p>• Work on projects with other programmers. Be the best programmer on some projects; be the worst on some others. When you&#8217;re the best, you get to test your abilities to lead a project, and to inspire others with your vision. When you&#8217;re the worst, you learn what the masters do, and you learn what they don&#8217;t like to do (because they make you do it for them).</p>
<p>• Work on projects after other programmers. Be involved in understanding a program written by someone else. See what it takes to understand and fix it when the original programmers are not around. Think about how to design your programs to make it easier for those who will maintain it after you.</p>
<p>• Remember that there is a &#8220;computer&#8221; in &#8220;computer science&#8221;. Know how long it takes your computer to execute an instruction, fetch a word from memory (with and without a cache miss), read consecutive words from disk, and seek to a new location on disk.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/uncategorized/recipe-for-programming-success/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detecting user inactivity/idle time since last touch on screen</title>
		<link>http://www.makebetterthings.com/iphone/detecting-user-inactivityidle-time-since-last-touch-on-screen/</link>
		<comments>http://www.makebetterthings.com/iphone/detecting-user-inactivityidle-time-since-last-touch-on-screen/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 10:37:15 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[touch]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/?p=255</guid>
		<description><![CDATA[Recently I required to find inactivity of screen in one of my iPad project.  Here is the steps by which I completed this task. Step 1 -  Add a class (IdleTimeCheck) in your project which subclass UIApplication. In the implementation file, override the sendEvent: method like so: where maxIdleTime and idleTimer are instance variables. Step [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I required to find inactivity of screen in one of my iPad project.  Here is the steps by which I completed this task.</p>
<p>Step 1 -  Add a class (IdleTimeCheck) in your project which subclass UIApplication. In the implementation file, override the sendEvent: method like so:</p>
<pre class="brush: objc; title: ; notranslate">

- (void)sendEvent:(UIEvent *)event {
[super sendEvent:event];

// Only want to reset the timer on a Began touch or an Ended touch, to reduce the number of timer resets.
NSSet *allTouches = [event allTouches];
if ([allTouches count] &gt; 0) {
// allTouches count only ever seems to be 1, so anyObject works here.
UITouchPhase phase = ((UITouch *)[allTouches anyObject]).phase;
if (phase == UITouchPhaseBegan || phase == UITouchPhaseEnded)
[self resetIdleTimer];
}
}

- (void)resetIdleTimer {
if (idleTimer) {
[idleTimer invalidate];
[idleTimer release];
}

idleTimer = [[NSTimer scheduledTimerWithTimeInterval:maxIdleTime target:self selector:@selector(idleTimerExceeded) userInfo:nil repeats:NO] retain];
}

- (void)idleTimerExceeded {
NSLog(@&quot;idle time exceeded&quot;);
}
</pre>
<p>where maxIdleTime and idleTimer are instance variables.</p>
<p>Step 2 &#8211; Modify your UIApplicationMain function in main.m file to use your UIApplication subclass class as principal class.</p>
<pre class="brush: objc; title: ; notranslate">
int retVal = UIApplicationMain(argc, argv, @&quot;IdleTimeCheck&quot;,nil);
</pre>
<p>And its done.</p>
<p>Hope it help someone who is looking for something like this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/iphone/detecting-user-inactivityidle-time-since-last-touch-on-screen/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Headphone plug-in plug-out event in iOS</title>
		<link>http://www.makebetterthings.com/iphone/headphone-plug-in-plug-out-event-in-ios/</link>
		<comments>http://www.makebetterthings.com/iphone/headphone-plug-in-plug-out-event-in-ios/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 10:43:25 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[hardware route]]></category>
		<category><![CDATA[headphone]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/?p=250</guid>
		<description><![CDATA[To get the headphone plug-in plug-out event we need to employ a property listener callback function. The system invokes the callback when a user plugs in or unplugs a headset, or docks or undoes the device &#8211; thereby adding or removing an audio connection. The system also invokes the property listener callback when a Bluetooth [...]]]></description>
			<content:encoded><![CDATA[<p>To get the headphone plug-in plug-out event we need to employ a property listener callback function. The system invokes the callback when a user plugs in or unplugs a headset, or docks or undoes the device &#8211; thereby adding or removing an audio connection. The system also invokes the property listener callback when a Bluetooth device connects or disconnects.</p>
<p>Defining a Property Listener Callback Function</p>
<p>To respond to a route change, a property listener callback function must:</p>
<ul>
<li>Identify the nature of the route change</li>
<li>Branch, depending on the specific route change and the current audio context (for example, recording, playback, or stopped)</li>
<li>Take or invoke appropriate action</li>
</ul>
<p>Here is the example of this type of callback function. To see a similar callback function in working project you should see AddMusic sample code by Apple.</p>
<pre class="brush: objc; title: ; notranslate">
void audioRouteChangeListenerCallback (
void                   *inUserData,                                 // 1
AudioSessionPropertyID inPropertyID,                                // 2
UInt32                 inPropertyValueSize,                         // 3
const void             *inPropertyValue                             // 4
)

{

if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return; // 5
MainViewController *controller = (MainViewController *) inUserData; // 6
if (controller.appSoundPlayer.playing == 0 ) {                      // 7
return;
} else {
CFDictionaryRef routeChangeDictionary = inPropertyValue;        // 8
CFNumberRef routeChangeReasonRef = CFDictionaryGetValue (routeChangeDictionary,CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
SInt32 routeChangeReason;
CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &amp;routeChangeReason);
if (routeChangeReason ==  kAudioSessionRouteChangeReason_OldDeviceUnavailable) {  // 9

[controller.appSoundPlayer pause];
UIAlertView *routeChangeAlertView =    [[UIAlertView alloc] initWithTitle: @&quot;Playback Route Changed&quot;  message: @&quot;Audio output was changed.&quot; delegate:nil cancelButtonTitle: @&quot;Ok&quot; otherButtonTitles:nil];
[routeChangeAlertView show];

}

}

}
</pre>
<p>Here’s how this code works:</p>
<ol>
<li>A pointer to data that you provide when initializing your audio session.In an Objective-C class file, such as a view controller class, you place the property listener callback function outside of the class implementation block. Because of this, the callback needs a reference to the controller object to be able to send messages to it. You provide this reference when initializing your audio session.</li>
<li>The identifier for the property that this callback function gets notified about.</li>
<li>The size, in bytes, of the data in the <em>inPropertyValue</em> parameter.</li>
<li>The current value of the property that this callback function is monitoring. Because the property being monitored is the <code>kAudioSessionProperty_AudioRouteChange</code> property, this value is a <code>CFDictionary</code> object.</li>
<li>Ensures that the callback was invoked for the correct audio session property change.</li>
<li>Initializes a <code>MainViewController</code> object instance to the reference passed in by the <em>inUserData</em> parameter. This allows the callback to send messages to your view controller object—typically defined in the same file that implements the callback.</li>
<li>If application sound is not playing, there&#8217;s nothing to do, so return.</li>
<li>This line and the next several lines determine the reason for the route change. The one route change of interest in this playback-only example is that an output device, such as a headset, was removed.</li>
<li>If an output device was indeed removed, then pause playback and display an alert that allows the user to stop or resume playback.</li>
</ol>
<p><strong>Registering Your Property Listener Callback with the Audio Session</strong></p>
<p>Your application can listen for hardware and route change events by way of the property mechanism in Audio Session Services. For example, to listen for route change events, you register a callback function with your audio session object, as shown here.</p>
<pre class="brush: objc; title: ; notranslate">
AudioSessionPropertyID routeChangeID =  kAudioSessionProperty_AudioRouteChange;    // 1

AudioSessionAddPropertyListener (                                  // 2

routeChangeID,                                                 // 3

audioRouteChangeListenerCallback,                                      // 4

userData                                                       // 5

);
</pre>
<p>Here’s how this code works:</p>
<ol>
<li>Declares and initializes a variable to the identifier for the property you want to monitor.</li>
<li>Registers your property listener callback function with your initialized audio session.</li>
<li>The identifier for the property you want to monitor.</li>
<li>A reference to your hardware listener callback function.</li>
<li>Data you want the audio session to pass back to your callback function.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/iphone/headphone-plug-in-plug-out-event-in-ios/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Automatic Reference Counting (ARC) in Xcode 4.2</title>
		<link>http://www.makebetterthings.com/iphone/automatic-reference-counting-arc-in-xcode-4-2/</link>
		<comments>http://www.makebetterthings.com/iphone/automatic-reference-counting-arc-in-xcode-4-2/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 12:54:01 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[xcode]]></category>
		<category><![CDATA[ARC]]></category>
		<category><![CDATA[iOS 5]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Xcode 4.2]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/?p=246</guid>
		<description><![CDATA[Xcode 4.2 now includes a new feature called Automatic Reference Counting aka. ARC which automates memory management for Objective-C objects. ARC makes memory management much easier, greatly reducing the chance that your program will have memory leaks. First, Xcode reviews your project to determine whether there are items that cannot be converted (and that you [...]]]></description>
			<content:encoded><![CDATA[<p>Xcode 4.2 now includes a new feature called Automatic Reference Counting aka. ARC which automates memory management for Objective-C objects. ARC makes memory management much easier, greatly reducing the chance that your program will have memory leaks. First, Xcode reviews your project to determine whether there are items that cannot be converted (and that you must therefore change manually). Then, Xcode rewrites your source code to use ARC.</p>
<p>ARC works by adding code at compile time to ensure that objects live as long as necessary, but no longer. Conceptually, it follows the same memory management conventions as manual reference counting, by adding the appropriate retain, release, and autorelease method calls for you.</p>
<p>ARC is supported in Xcode 4.2 for Mac OS X v10.6 and v10.7 (64-bit applications) and for iOS 4 and iOS 5. Weak references are not supported in Mac OS X v10.6 and iOS 4.</p>
<p>Instead of you having to remember when to use retain, release, and autorelease, ARC evaluates the lifetime requirements of your objects and automatically inserts the appropriate method calls for you at compile time. The compiler also generates appropriate dealloc methods for you. In general, if you’re only using ARC the traditional Cocoa naming conventions are important only if you need to interoperate with code that uses manual reference counting.</p>
<p>A complete and correct implementation of a Person class might look like this:</p>
<pre class="brush: objc; title: ; notranslate">
@interface Person : NSObject
@property (nonatomic, strong) NSString *firstName;
@property (nonatomic, strong) NSString *lastName;
@property (nonatomic, strong) NSNumber *yearOfBirth;
@property (nonatomic, strong) Person *spouse;
@end

@implementation Person
@synthesize firstName, lastName, yearOfBirth, spouse;
@end
</pre>
<p>Using ARC, you could implement a contrived method like this:</p>
<pre class="brush: objc; title: ; notranslate">
- (void)contrived {
    Person *aPerson = [[Person alloc] init];
    [aPerson setFirstName:@&quot;William&quot;];
    [aPerson setLastName:@&quot;Dudney&quot;];
    [aPerson:setYearOfBirth:[[NSNumber alloc] initWithInteger:2011]];
    NSLog(@&quot;aPerson: %@&quot;, aPerson);
}
</pre>
<p>ARC takes care of memory management so that neither the Person nor the NSNumber objects are leaked.</p>
<p>You could also safely implement a takeLastNameFrom: method of Person like this:</p>
<pre class="brush: objc; title: ; notranslate">
- (void)takeLastNameFrom:(Person *)person {
    NSString *oldLastname = [self lastName];
    [self setLastName:[person lastName]];
    NSLog(@&quot;Lastname changed from %@ to %@&quot;, oldLastname, [self lastName]);
}
</pre>
<p>ARC ensures that oldLastName is not deallocated before the NSLog statement.</p>
<p><strong>ARC Enforces New Rules</strong><br />
To work, ARC imposes some new rules that are not present when using other compiler modes. The rules are intended to provide a fully reliable memory management model; in some cases, they simply enforce best practice, in some others they simplify your code or are obvious corollaries of your not having to deal with memory management. If you violate these rules, you get an immediate compile-time error, not a subtle bug that may become apparent at runtime.</p>
<ul>
<li>You cannot explicitly invoke dealloc, or implement or invoke retain, release, retainCount, or autorelease.The prohibition extends to using @selector(retain), @selector(release), and so on.
<p>You may implement a dealloc method if you need to manage resources other than releasing instance variables. You do not have to (indeed you cannot) release instance variables, but you may need to invoke [systemClassInstance setDelegate:nil] on system classes and other code that isn’t compiled using ARC.</p>
<p>Custom dealloc methods in ARC do not require a call to [super dealloc] (it actually results in a compiler error). The chaining to super is automated and enforced by the compiler.</p>
<p>You can still use CFRetain, CFRelease, and other related functions with Core Foundation-style objects (see “Managing Toll-Free Bridging”).</li>
<li>You cannot use NSAllocateObject or NSDeallocateObject.You create objects using alloc; the runtime takes care of deallocating objects.</li>
<li>You cannot use object pointers in C structures.Rather than using a struct, you can create an Objective-C class to manage the data instead.</li>
<li>There is no casual casting between id and void *.You must use special casts that tell the compiler about object lifetime. You need to do this to cast between Objective-C objects and Core Foundation types that you pass as function arguments. For more details, see “Managing Toll-Free Bridging”.</li>
<li>Cannot use NSAutoreleasePool objects.ARC provides @autoreleasepool blocks instead. These have an advantage of being more efficient than NSAutoreleasePool.</li>
<li>You cannot use memory zones. There is no need to use NSZone any more—they are ignored by the modern Objective-C runtime anyway.</li>
</ul>
<p>To allow interoperation with manual retain-release code, ARC imposes some constraints on method and variable naming:</p>
<p>You cannot give a property a name that begins with new.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/iphone/automatic-reference-counting-arc-in-xcode-4-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Where is MainWindow.xib in Xcode 4.2 ?</title>
		<link>http://www.makebetterthings.com/iphone/where-is-mainwindow-xib-in-xcode-4-2/</link>
		<comments>http://www.makebetterthings.com/iphone/where-is-mainwindow-xib-in-xcode-4-2/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 17:45:10 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[xcode]]></category>
		<category><![CDATA[MainWindow.xib]]></category>
		<category><![CDATA[Xcode 4.2]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/?p=223</guid>
		<description><![CDATA[In Xcode 4.2 the MainWindow.xib is not included for some of the project templates. Its means now we have to generate GUI elements by code or we can reconstruct the MainWindow.xib in project. I am describing you the second option here. If you create a new project in XCode 4.2, and choose the Empty Application [...]]]></description>
			<content:encoded><![CDATA[<p>In Xcode 4.2 the MainWindow.xib is not included for some of the project templates. Its means now we have to generate GUI elements by code or we can reconstruct the MainWindow.xib in project. I am describing you the second option here.</p>
<p>If you create a new project in XCode 4.2, and choose the Empty Application template to start from, change nothing and try running it in your iPhone 5.0 simulator, you will see an empty – black – screen. The only thing you get from the template is an AppDelegate.h and AppDelegate.m.</p>
<p>We&#8217;ll now reconstruct the MainWindow.xib file in our project. So the next thing is now to create a empty user interface file. Choose iOS &gt; User Interface &gt; Empty as template. The name of this file is not very important but we&#8217;ll use MainWindow.xib because this name is familiar to us.</p>
<p><a href="http://www.makebetterthings.com/iphone/where-is-mainwindow-xib-in-xcode-4-2/attachment/screen-shot-2011-10-27-at-10-34-52-pm/" rel="attachment wp-att-224"><img class="alignnone size-full wp-image-224" title="Screen Shot 2011-10-27 at 10.34.52 PM" src="http://www.makebetterthings.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-27-at-10.34.52-PM.png" alt="" width="704" height="473" /></a></p>
<p>Now select the Empty MainWindow.xib file we just created in previous step.</p>
<p><a href="http://www.makebetterthings.com/iphone/where-is-mainwindow-xib-in-xcode-4-2/attachment/screen-shot-2011-10-27-at-10-35-37-pm/" rel="attachment wp-att-225"><img title="Screen Shot 2011-10-27 at 10.35.37 PM" src="http://www.makebetterthings.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-27-at-10.35.37-PM.png" alt="" width="648" height="243" /></a></p>
<p>Change the Class of File&#8217;s Owner to UIApplication</p>
<p><a href="http://www.makebetterthings.com/iphone/where-is-mainwindow-xib-in-xcode-4-2/attachment/screen-shot-2011-10-27-at-10-36-11-pm/" rel="attachment wp-att-226"><img class="alignnone size-full wp-image-226" title="Screen Shot 2011-10-27 at 10.36.11 PM" src="http://www.makebetterthings.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-27-at-10.36.11-PM.png" alt="" width="715" height="95" /></a></p>
<p>Now drop a Object from Library to Objects in xib file.</p>
<p><a href="http://www.makebetterthings.com/iphone/where-is-mainwindow-xib-in-xcode-4-2/attachment/screen-shot-2011-10-27-at-10-36-31-pm/" rel="attachment wp-att-228"><img class="alignnone size-full wp-image-228" title="Screen Shot 2011-10-27 at 10.36.31 PM" src="http://www.makebetterthings.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-27-at-10.36.31-PM.png" alt="" width="674" height="279" /></a></p>
<p>Change the class of that object to the AppDelegate class</p>
<p><a href="http://www.makebetterthings.com/iphone/where-is-mainwindow-xib-in-xcode-4-2/attachment/screen-shot-2011-10-27-at-10-36-56-pm-2/" rel="attachment wp-att-231"><img class="alignnone size-full wp-image-231" title="Screen Shot 2011-10-27 at 10.36.56 PM" src="http://www.makebetterthings.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-27-at-10.36.56-PM1.png" alt="" width="683" height="178" /></a>sd</p>
<p>Now add a window to objects pane.</p>
<div><a href="http://www.makebetterthings.com/iphone/where-is-mainwindow-xib-in-xcode-4-2/attachment/screen-shot-2011-10-27-at-10-55-44-pm/" rel="attachment wp-att-232"><img class="alignnone size-large wp-image-232" title="Screen Shot 2011-10-27 at 10.55.44 PM" src="http://www.makebetterthings.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-27-at-10.55.44-PM-400x112.png" alt="" width="400" height="112" /></a></div>
<div>Now we need to bind this window object to our code. To do this we have to add IBOutlet to window object in AppDelegate.h file. You code of AppDelegate.h should look like this -</div>
<div>
<pre class="brush: objc; title: ; notranslate">&lt;/pre&gt;
#import &lt;UIKit/UIKit.h&gt;

@interface AppDelegate : UIResponder &lt;UIApplicationDelegate&gt;

@property (strong, nonatomic) IBOutlet UIWindow *window;

@end
</pre>
<p>Note the IBOutlet just before UIWindow.</p>
<p>Now continue with editing MainWindow.xib file -</p>
<p>Control-Drag from the <em>delegate</em> outlet of the File Owner to the xAppDelegate object.</p>
<p><a href="http://www.makebetterthings.com/iphone/where-is-mainwindow-xib-in-xcode-4-2/attachment/screen-shot-2011-10-27-at-11-05-07-pm-2/" rel="attachment wp-att-235"><img class="alignnone size-large wp-image-235" title="Screen Shot 2011-10-27 at 11.05.07 PM" src="http://www.makebetterthings.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-27-at-11.05.07-PM1-400x118.png" alt="" width="400" height="118" /></a></p>
<p>Control-Drag from the <em>window</em> outlet of the xAppDelegate to the Window.</p>
<p><a href="http://www.makebetterthings.com/iphone/where-is-mainwindow-xib-in-xcode-4-2/attachment/screen-shot-2011-10-27-at-10-37-57-pm/" rel="attachment wp-att-236"><img class="alignnone size-large wp-image-236" title="Screen Shot 2011-10-27 at 10.37.57 PM" src="http://www.makebetterthings.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-27-at-10.37.57-PM-400x96.png" alt="" width="400" height="96" /></a></p>
<p>Navigate to the project, and in the Summary tab, select MainWindow as the Main Interface.</p>
<p><a href="http://www.makebetterthings.com/iphone/where-is-mainwindow-xib-in-xcode-4-2/attachment/screen-shot-2011-10-27-at-10-38-39-pm/" rel="attachment wp-att-237"><img class="alignnone size-large wp-image-237" title="Screen Shot 2011-10-27 at 10.38.39 PM" src="http://www.makebetterthings.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-27-at-10.38.39-PM-400x163.png" alt="" width="400" height="163" /></a></p>
<p>We are almost done now..  But there is one more thing we need to fix. In <em>AppDelegate.m</em>, there was actually code that creates a window as well, so we have to delete this code.</p>
<pre class="brush: objc; title: ; notranslate">
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
</pre>
<p>We are done now</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/iphone/where-is-mainwindow-xib-in-xcode-4-2/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Dennis Ritchie 1941 – 2011</title>
		<link>http://www.makebetterthings.com/uncategorized/dennis-ritchie-1941-%e2%80%93-2011/</link>
		<comments>http://www.makebetterthings.com/uncategorized/dennis-ritchie-1941-%e2%80%93-2011/#comments</comments>
		<pubDate>Sun, 23 Oct 2011 13:11:14 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/?p=212</guid>
		<description><![CDATA[So finally god needed the Unix master after getting Steve Jobs there… something is really cooking up there in the heavens. You were my hero dmr.. and you always be… May his soul and the souls of all the departed faithful by God’s mercy rest in peace. Thanks for everything… We all love you..]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.makebetterthings.com/uncategorized/dennis-ritchie-1941-%e2%80%93-2011/attachment/dennis_ritchie/" rel="attachment wp-att-213"><img class="size-full wp-image-213 alignleft" style="padding: 10px 10px 10px 10px;" title="dennis_ritchie" src="http://www.makebetterthings.com/wp-content/uploads/2011/10/dennis_ritchie.jpg" alt="" width="309" height="400" /></a></p>
<p>So finally god needed the Unix master after getting Steve Jobs there… something is really cooking up there in the heavens.<br />
You were my hero dmr.. and you always be…<br />
May his soul and the souls of all the departed faithful by God’s mercy rest in peace.<br />
Thanks for everything… We all love you..</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/uncategorized/dennis-ritchie-1941-%e2%80%93-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Steve Jobs 1955-2011</title>
		<link>http://www.makebetterthings.com/uncategorized/steve-jobs-1955-2011/</link>
		<comments>http://www.makebetterthings.com/uncategorized/steve-jobs-1955-2011/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 07:33:32 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/blogs/?p=207</guid>
		<description><![CDATA[Goodbye, Steve.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.makebetterthings.com/wp-content/uploads/2011/10/2011-10-06-jobs.png"><img class="aligncenter size-full wp-image-208" title="2011-10-06-jobs" src="http://www.makebetterthings.com/wp-content/uploads/2011/10/2011-10-06-jobs.png" alt="" width="620" height="454" /></a></p>
<p>This is the single suckiest home page I think I’ve ever seen. Not because it’s not well done, but because the news it represents is…heartbreaking.</p>
<p>It hurts even more because, despite all of Steve’s wealth, power, influence, and success, the simple truth is that human is human. No matter who you are, you are still mortal.</p>
<p>It’s that truth of human frailty, manifested in someone so focused on perfection in all things, that truly gives me pause tonight. It takes my breath away. It’s just so sad.</p>
<p>Goodbye, Steve.<br />
Thanks for everything!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/uncategorized/steve-jobs-1955-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Disable multitasking support in iOS 4 app</title>
		<link>http://www.makebetterthings.com/iphone/disable-multitasking-support-in-ios-4-app/</link>
		<comments>http://www.makebetterthings.com/iphone/disable-multitasking-support-in-ios-4-app/#comments</comments>
		<pubDate>Wed, 28 Sep 2011 09:04:45 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[multitasking]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/blogs/?p=205</guid>
		<description><![CDATA[You can disable multitasking in iOS 4+ app just by adding a 'UIApplicationExitsOnSuspend' key in your info.plist file.]]></description>
			<content:encoded><![CDATA[<p>Multitasking support is enabled by default in all iOS 4+ application. There can be situations where you need to disable this support (if you don&#8217;t want your app to run in background).<br />
You can disable multitasking in iOS 4+ app just by adding a key in your info.plist file. </p>
<p>You just need to add this following key (right click on your info.plist file and open as plain text file) &#8211; </p>
<pre class="brush: objc; title: ; notranslate">
&lt;key&gt;UIApplicationExitsOnSuspend&lt;/key&gt;
	&lt;true/&gt;
</pre>
<p>If you are using visual editor to edit info.plist file the just click on &#8220;+&#8221; button and add &#8216;UIApplicationExitsOnSuspend&#8217; key and press tab key and select the check mark. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/iphone/disable-multitasking-support-in-ios-4-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove NSLog from whole xcode project</title>
		<link>http://www.makebetterthings.com/xcode/remove-nslog-from-whole-xcode-project/</link>
		<comments>http://www.makebetterthings.com/xcode/remove-nslog-from-whole-xcode-project/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 13:41:12 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[xcode]]></category>
		<category><![CDATA[xcode4]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/blogs/?p=198</guid>
		<description><![CDATA[This is very good optimization if you remove all your NSLog statement from project. But its hard to find every NSLog and remove it if you have a big project.]]></description>
			<content:encoded><![CDATA[<p>This is very good optimization if you remove all your NSLog statement from project. But its hard to find every NSLog and remove it if you have a big project. Well here are two tips -</p>
<p><strong>1)</strong> Use ifndef to replace NSLog with blank. Here is an example -</p>
<pre class="brush: objc; title: ; notranslate">
#ifndef __OPTIMIZE__
#define NSLog(...) NSLog(__VA_ARGS__)
#else
#define NSLog(...) {}
#endif
</pre>
<p><strong>2)</strong> User regular expression in Find and replace to remove NSLogs</p>
<p>a) Press command + shift + f to open find and replace in whole project.<br />
b) Search for</p>
<blockquote><p>NSLog.*;</p></blockquote>
<p>and replace it with blank</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/xcode/remove-nslog-from-whole-xcode-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NSString Format Specifiers</title>
		<link>http://www.makebetterthings.com/objective-c/nsstring-format-specifiers/</link>
		<comments>http://www.makebetterthings.com/objective-c/nsstring-format-specifiers/#comments</comments>
		<pubDate>Sat, 03 Sep 2011 11:30:20 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[NSString]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/blogs/?p=195</guid>
		<description><![CDATA[Do you ever got confused when you want to NSLog a long integer? What to use to print a long %ld or %lx or %f or %d. Well Here is a complete list of all the NSString format specifiers]]></description>
			<content:encoded><![CDATA[<p>Do you ever got confused when you want to NSLog a long integer? What to use to print a long %ld or %lx or %f or %d. Well Here is a complete list of all the NSString format specifiers -</p>
<table border="0" cellspacing="0" cellpadding="5" width="588">
<tbody>
<tr>
<td><strong>Specifier</strong></td>
<td><strong>Description</strong></td>
</tr>
<tr>
<td scope="row"><code>%@</code></td>
<td>Objective-C object, printed as the string returned by <code>descriptionWithLocale:</code> if available, or <code>description</code> otherwise. Also works with <code>CFTypeRef</code> objects, returning the result of the <code>CFCopyDescription</code> function.</td>
</tr>
<tr>
<td scope="row"><code>%%</code></td>
<td><code>'%'</code> character</td>
</tr>
<tr>
<td scope="row"><code>%d</code>, <code>%D</code>, <code>%i</code></td>
<td>Signed 32-bit integer (<code>int</code>)</td>
</tr>
<tr>
<td scope="row"><code>%u</code>, <code>%U</code></td>
<td>Unsigned 32-bit integer (<code>unsigned int</code>)</td>
</tr>
<tr>
<td scope="row"><code>%hi</code></td>
<td>Signed 16-bit integer (<code>short</code>)</td>
</tr>
<tr>
<td scope="row"><code>%hu</code></td>
<td>Unsigned 16-bit integer (<code>unsigned short</code>)</td>
</tr>
<tr>
<td scope="row"><code>%qi</code></td>
<td>Signed 64-bit integer (<code>long long</code>)</td>
</tr>
<tr>
<td scope="row"><code>%qu</code></td>
<td>Unsigned 64-bit integer (<code>unsigned long long</code>)</td>
</tr>
<tr>
<td scope="row"><code>%x</code></td>
<td>Unsigned 32-bit integer (<code>unsigned int</code>), printed in hexadecimal using the digits 0–9 and lowercase a–f</td>
</tr>
<tr>
<td scope="row"><code>%X</code></td>
<td>Unsigned 32-bit integer (<code>unsigned int</code>), printed in hexadecimal using the digits 0–9 and uppercase A–F</td>
</tr>
<tr>
<td scope="row"><code>%qx</code></td>
<td>Unsigned 64-bit integer (<code>unsigned long long</code>), printed in hexadecimal using the digits 0–9 and lowercase a–f</td>
</tr>
<tr>
<td scope="row"><code>%qX</code></td>
<td>Unsigned 64-bit integer (<code>unsigned long long</code>), printed in hexadecimal using the digits 0–9 and uppercase A–F</td>
</tr>
<tr>
<td scope="row"><code>%o</code>, <code>%O</code></td>
<td>Unsigned 32-bit integer (<code>unsigned int</code>), printed in octal</td>
</tr>
<tr>
<td scope="row"><code>%f</code></td>
<td>64-bit floating-point number (<code>double</code>)</td>
</tr>
<tr>
<td scope="row"><code>%e</code></td>
<td>64-bit floating-point number (<code>double</code>), printed in scientific notation using a lowercase e to introduce the exponent</td>
</tr>
<tr>
<td scope="row"><code>%E</code></td>
<td>64-bit floating-point number (<code>double</code>), printed in scientific notation using an uppercase E to introduce the exponent</td>
</tr>
<tr>
<td scope="row"><code>%g</code></td>
<td>64-bit floating-point number (<code>double</code>), printed in the style of <code>%e</code> if the exponent is less than –4 or greater than or equal to the precision, in the style of <code>%f</code> otherwise</td>
</tr>
<tr>
<td scope="row"><code>%G</code></td>
<td>64-bit floating-point number (<code>double</code>), printed in the style of <code>%E</code> if the exponent is less than –4 or greater than or equal to the precision, in the style of <code>%f</code> otherwise</td>
</tr>
<tr>
<td scope="row"><code>%c</code></td>
<td>8-bit unsigned character (<code>unsigned char</code>), printed by <code>NSLog()</code> as an ASCII character, or, if not an ASCII character, in the octal format <code>\ddd</code> or the Unicode hexadecimal format <code>\udddd</code>, where <code>d</code> is a digit</td>
</tr>
<tr>
<td scope="row"><code>%C</code></td>
<td>16-bit Unicode character (<code>unichar</code>), printed by <code>NSLog()</code> as an ASCII character, or, if not an ASCII character, in the octal format <code>\ddd</code> or the Unicode hexadecimal format <code>\udddd</code>, where <code>d</code> is a digit</td>
</tr>
<tr>
<td scope="row"><code>%s</code></td>
<td>Null-terminated array of 8-bit unsigned characters. <code>%s</code> interprets its input in the system encoding rather than, for example, UTF-8.</td>
</tr>
<tr>
<td scope="row"><code>%S</code></td>
<td>Null-terminated array of 16-bit Unicode characters</td>
</tr>
<tr>
<td scope="row"><code>%p</code></td>
<td>Void pointer (<code>void *</code>), printed in hexadecimal with the digits 0–9 and lowercase a–f, with a leading <code>0x</code></td>
</tr>
<tr>
<td scope="row"><code>%L</code></td>
<td>Length modifier specifying that a following <code>a</code>, <code>A</code>, <code>e</code>, <code>E</code>, <code>f</code>, <code>F</code>, <code>g</code>, or <code>G</code> conversion specifier applies to a <code>long double</code> argument</td>
</tr>
<tr>
<td scope="row"><code>%a</code></td>
<td>64-bit floating-point number (<code>double</code>), printed in scientific notation with a leading <code>0x</code> and one hexadecimal digit before the decimal point using a lowercase <code>p</code> to introduce the exponent</td>
</tr>
<tr>
<td scope="row"><code>%A</code></td>
<td>64-bit floating-point number (<code>double</code>), printed in scientific notation with a leading <code>0X</code> and one hexadecimal digit before the decimal point using a uppercase <code>P</code> to introduce the exponent</td>
</tr>
<tr>
<td scope="row"><code>%F</code></td>
<td>64-bit floating-point number (<code>double</code>), printed in decimal notation</td>
</tr>
<tr>
<td scope="row"><code>%z</code></td>
<td>Length modifier specifying that a following <code>d</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>x</code>, or <code>X</code> conversion specifier applies to a <code>size_t</code> or the corresponding signed integer type argument</td>
</tr>
<tr>
<td scope="row"><code>%t</code></td>
<td>Length modifier specifying that a following <code>d</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>x</code>, or <code>X</code> conversion specifier applies to a <code>ptrdiff_t</code> or the corresponding unsigned integer type argument</td>
</tr>
<tr>
<td scope="row"><code>%j</code></td>
<td>Length modifier specifying that a following <code>d</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>x</code>, or <code>X</code> conversion specifier applies to a <code>intmax_t</code> or <code>uintmax_t</code> argument</td>
</tr>
</tbody>
</table>
<p>Hope it will save someone time!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/objective-c/nsstring-format-specifiers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to find IP Address of iPhone</title>
		<link>http://www.makebetterthings.com/iphone/how-to-find-ip-address-of-iphone/</link>
		<comments>http://www.makebetterthings.com/iphone/how-to-find-ip-address-of-iphone/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 17:31:19 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[ip address]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/blogs/?p=190</guid>
		<description><![CDATA[Programmatically get IP Address of iPhone/iPad/iPod]]></description>
			<content:encoded><![CDATA[<p>The iOS SDK does not provide any simple way to get IP address of device programmatically. So the only way left is to get it by c code. So here we go -</p>
<p><strong>Step 1 &#8211; </strong>Add these header file in your code -</p>
<pre class="brush: objc; title: ; notranslate">
 #include &amp;amp;lt;ifaddrs.h&amp;amp;gt;
#include &amp;amp;lt;arpa/inet.h&amp;amp;gt;
 </pre>
<p><strong>Step 2 &#8211; </strong>And here is the real code -</p>
<pre class="brush: objc; title: ; notranslate">

- (NSString *)getIPAddress { 

	NSString *address = @&amp;amp;quot;error&amp;amp;quot;;
	struct ifaddrs *interfaces = NULL;
	struct ifaddrs *temp_addr = NULL;
	int success = 0;
	// retrieve the current interfaces - returns 0 on success
	success = getifaddrs(&amp;amp;amp;interfaces);
	if (success == 0) {
		// Loop through linked list of interfaces
		temp_addr = interfaces;
		while(temp_addr != NULL) {
			if(temp_addr-&amp;amp;gt;ifa_addr-&amp;amp;gt;sa_family == AF_INET) {
				// Check if interface is en0 which is the wifi connection on the iPhone
				if([[NSString stringWithUTF8String:temp_addr-&amp;amp;gt;ifa_name] isEqualToString:@&amp;amp;quot;en0&amp;amp;quot;]) {
					// Get NSString from C String
					address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr-&amp;amp;gt;ifa_addr)-&amp;amp;gt;sin_addr)]; 

				} 

			} 

			temp_addr = temp_addr-&amp;amp;gt;ifa_next;
		}
	}
	// Free memory
	freeifaddrs(interfaces);
	return address; 

} 
</pre>
<p>Hope it saves someone&#8217;s time!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/iphone/how-to-find-ip-address-of-iphone/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to “add existing frameworks” in Xcode 4?</title>
		<link>http://www.makebetterthings.com/iphone/how-to-%e2%80%9cadd-existing-frameworks%e2%80%9d-in-xcode-4/</link>
		<comments>http://www.makebetterthings.com/iphone/how-to-%e2%80%9cadd-existing-frameworks%e2%80%9d-in-xcode-4/#comments</comments>
		<pubDate>Sun, 03 Jul 2011 13:40:20 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[xcode]]></category>
		<category><![CDATA[xcode4]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/blogs/?p=184</guid>
		<description><![CDATA[Are you not getting how to add existing frameworks in xcode 4?]]></description>
			<content:encoded><![CDATA[<p>Are you not getting how to add existing frameworks in xcode 4?<br />
Well here is the right way of doing it -</p>
<p>1. In the project navigator, select your project<br />
2. Select your target<br />
3. Select the &#8216;Build Phases&#8217; tab<br />
4. Open &#8216;Link Binaries With Libraries&#8217; expander<br />
5. Click the &#8216;+&#8217; button<br />
6. Select your framework<br />
7. (optional) Drag and drop the added framework to the &#8216;Frameworks&#8217; group</p>
<p style="text-align: center;"><a href="http://www.makebetterthings.com/wp-content/uploads/2011/07/add-existing-frameworks-in-Xcode-4.jpg"><img class="aligncenter size-full wp-image-185" title="add existing frameworks in Xcode 4" src="http://www.makebetterthings.com/wp-content/uploads/2011/07/add-existing-frameworks-in-Xcode-4.jpg" alt="" width="611" height="198" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/iphone/how-to-%e2%80%9cadd-existing-frameworks%e2%80%9d-in-xcode-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Singleton Design Pattern for Objective-C</title>
		<link>http://www.makebetterthings.com/iphone/singleton-design-pattern-for-objective-c/</link>
		<comments>http://www.makebetterthings.com/iphone/singleton-design-pattern-for-objective-c/#comments</comments>
		<pubDate>Sun, 12 Jun 2011 05:28:21 +0000</pubDate>
		<dc:creator>Saurabh</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://www.makebetterthings.com/blogs/?p=178</guid>
		<description><![CDATA[A singleton class in an object-oriented application always returns the same instance of itself. It provides a global access point for the resources provided by the object of the class.]]></description>
			<content:encoded><![CDATA[<p><strong>Well first of all what is a singleton design pattern -</strong></p>
<p>A singleton class in an object-oriented application always returns the same instance of itself. It provides a global access point for the resources provided by the object of the class. A design pattern that is related to these kinds of designs is  called the Singleton pattern.</p>
<p><strong>When Would You Use the Singleton Pattern?</strong></p>
<ul>
<li> There must be exactly one instance of a class with which it must be accessible from a well-known access point.</li>
<li>The sole instance can be extended only by subclassing, and it won’t break client code with the extended object.</li>
</ul>
<p>The Singleton pattern provides a well-known access point to client classes that want to create a unique instance of and access to a shared resource. Although a static global object reference or a class method can provide a global access point, the global object cannot prevent the class getting instantiated more than once, and the class method lacks the flexibility of decoupling.</p>
<p>A static global variable holds a single reference to an instance of a class. Another class or a method that can access that global variable is, in fact, sharing the same copy with other classes or methods that use the same variable. That sounds like what we are after in this chapter. Everything seems fine if we use only the same global variable throughout the whole application. So, in fact, we don’t need the Singleton pattern. But hey, wait a minute; what if there is somebody in your team or a consultant who has defined the same type of static global variable as yours? Then there will be two copies of the same global object type living in the same application—so a global variable doesn’t really solve the problem.</p>
<p>A class method provides shared services without creating an object of it. A single instance of the resource is maintained within the class method. However, this approach lacks the flexibility if the class needs to be subclassed to provide better services.</p>
<p>A singleton class can guarantee a single, consistent, and well-known access point to create and access a single object of the class. The pattern provides the flexibility such that any of its subclasses can override the instance method and have total control over object creation of itself without changing code in the client. Or even better, the instance implementation in the parent class can handle dynamic object creation. The actual type of a class can be determined to make sure the correct object is created at runtime. This technique will be discussed later in the chapter.</p>
<p><strong>Implementing a Singleton in Objective-C -</strong></p>
<pre><strong>MySingleton.h</strong>
<pre class="brush: objc; title: ; notranslate">
#import &lt;Foundation/Foundation.h&gt;

@interface MySingleton : NSObject {

}

+ (MySingleton*) sharedInstance;

@end
</pre>
<p><strong>MySingleton.m</strong></p>
<pre class="brush: objc; title: ; notranslate">

#import &quot;MySingleton.h&quot;

static MySingleton *_instance;
@implementation MySingleton

#pragma mark -
#pragma mark Singleton Methods

+ (MySingleton*)sharedInstance
{
 @synchronized(self) {

 if (_instance == nil) {

 _instance = [[self alloc] init];

 // Allocate/initialize any member variables of the singleton class here
 // example
 //_instance.member = @&quot;&quot;;
 }
 }
 return _instance;
}

+ (id)allocWithZone:(NSZone *)zone

{
 @synchronized(self) {

 if (_instance == nil) {

 _instance = [super allocWithZone:zone];
 return _instance;  // assignment and return on first allocation
 }
 }

 return nil; //on subsequent allocation attempts return nil
}

- (id)copyWithZone:(NSZone *)zone
{
 return self;
}

- (id)retain
{
 return self;
}

- (unsigned)retainCount
{
 return UINT_MAX;  //denotes an object that cannot be released
}

- (void)release
{
 //do nothing
}

- (id)autorelease
{
 return self;
}

#pragma mark -
#pragma mark Custom Methods

// Add your custom methods here

@end
</pre>
<p>Visit Apple doc's this page for more info on Singleton Design Pattern -<br />
<a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html">http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html<br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.makebetterthings.com/iphone/singleton-design-pattern-for-objective-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

