<?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>Just2us &#187; tutorials</title>
	<atom:link href="http://just2us.com/tag/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://just2us.com</link>
	<description>Its about us</description>
	<lastBuildDate>Sat, 31 Jul 2010 16:03:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Pitfalls of NSFetchedResultsController</title>
		<link>http://just2us.com/2010/02/pitfalls-of-nsfetchedresultscontroller/</link>
		<comments>http://just2us.com/2010/02/pitfalls-of-nsfetchedresultscontroller/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 14:06:59 +0000</pubDate>
		<dc:creator>samwize</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[CoreData]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://just2us.com/2010/02/pitfalls-of-nsfetchedresultscontroller/</guid>
		<description><![CDATA[I have recently used one of the most useful framework in iPhone 3.0 – CoreData. There are many guides on using CoreData, such as from cocoadevcentral or Apple’s guide. But what I found lacking is that there was no discussion on the pitfalls of using CoreData, or its view controller, NSFetchedResultsController. I learnt the pitfalls [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjust2us.com%2F2010%2F02%2Fpitfalls-of-nsfetchedresultscontroller%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjust2us.com%2F2010%2F02%2Fpitfalls-of-nsfetchedresultscontroller%2F&amp;source=samwize&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I have recently used one of the most useful framework in iPhone 3.0 – CoreData. </p>
<p>There are many guides on using CoreData, such as from <a href="http://cocoadevcentral.com/articles/000086.php">cocoadevcentral</a> or <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CoreData/Articles/cdBasics.html#//apple_ref/doc/uid/TP40001650-TP1">Apple’s guide</a>. But what I found lacking is that there was no discussion on the pitfalls of using CoreData, or its view controller, <a href="http://developer.apple.com/iphone/library/documentation/CoreData/Reference/NSFetchedResultsController_Class/Reference/Reference.html">NSFetchedResultsController</a>.</p>
<p>I learnt the pitfalls along the way, and there are 3 particular pitfalls that I would like to share with developers while developing <a href="http://txeet.com">txeet</a> for iPhone.</p>
<p>&#160;</p>
<h2>1. Performance hit with predicate using one-to-many relationship</h2>
<p>When using NSFetchedResultsController, we would often form our predicate (like SQL) to retrieve some table rows. </p>
<p>If you were to use a predicate that involves transversing a one-to-many relationship, the performance could be slowed down <a href="http://stackoverflow.com/questions/1145178/core-data-fetching-objects-that-are-in-relationship-to-another-object">tremendously</a> (as slow as 30 sec to run, or even crash!). Take for example a <strong>Template</strong> model that has a one-to-many relationship <strong>tags</strong> to <strong>Tag</strong> model:</p>
<p><a href="http://just2us.com/site/wp-content/uploads/2010/02/coredatapitfallcode1.jpg"><img title="coredata pitfall code1" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="40" alt="coredata pitfall code1" src="http://just2us.com/site/wp-content/uploads/2010/02/coredatapitfallcode1_thumb.jpg" width="624" border="0" /></a>&#160; </p>
<p>The predicate above would require transversing to each Tag to find ‘love’. This is computationally <em>very expensive</em>. </p>
<p>The solution to this is to avoid transversing relationship. A faster way that CoreData could execute is to access the properties/attributes. For the above example, what I did is to add another attribute <strong>tagsAsAttribute</strong> to <strong>Template</strong> model. This property would store the tag names in a delimited format such as “;love;jokes;quotes;”. The predicate would then be changed to:</p>
<p><a href="http://just2us.com/site/wp-content/uploads/2010/02/coredatapitfallcode2.jpg"><img title="coredata pitfall code2" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="31" alt="coredata pitfall code2" src="http://just2us.com/site/wp-content/uploads/2010/02/coredatapitfallcode2_thumb.jpg" width="679" border="0" /></a> </p>
<p>Note: This is not the best way to design the data model, as <strong>tagsAsAttribute</strong> has a dependency and is redundant.</p>
<p>&#160;</p>
<h2>2. User-driven updates</h2>
<p>If you read the <a href="http://developer.apple.com/iphone/library/documentation/CoreData/Reference/NSFetchedResultsControllerDelegate_Protocol/Reference/Reference.html">Apple’s guide to NSFetchedResultsControllerDelegate</a>, please note of the section User-Driven Updates.</p>
<p>In short, if you have user-driven updates, you should write the following as the first line in every (only one is shown below) of the NSFetchedResultsControllerDelegate delegate methods:</p>
<p><a href="http://just2us.com/site/wp-content/uploads/2010/02/coredatapitfallcode3.jpg"><img title="coredata pitfall code3" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="37" alt="coredata pitfall code3" src="http://just2us.com/site/wp-content/uploads/2010/02/coredatapitfallcode3_thumb.jpg" width="557" border="0" /></a> </p>
<p>And when there is a user-driven update, set the <strong>isStillUpdating</strong> boolean to true, and set false when the update is completed.</p>
<p>User-driven updates could be re-ordering of table rows, or inserting of objects.</p>
<p>&#160;</p>
<h2>3. abort() should NEVER be used in release</h2>
<p>If you have used the sample code for CodeData, there is a line of code which is there only for testing environment. In the comments, it warned developers that <strong>abort()</strong> should not be used in shipping application..</p>
<p>But I didn’t read the comments..</p>
<p>Apparently, certain devices will occasionally have error when running certain CoreData methods. Eg. NSManagedObjectContext’s save. When there is an error, we could optionally handle the error, but we should NEVER abort and exit the app.</p>
]]></content:encoded>
			<wfw:commentRss>http://just2us.com/2010/02/pitfalls-of-nsfetchedresultscontroller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to obfuscate an Android application</title>
		<link>http://just2us.com/2009/07/tutorial-obfuscate-an-android-application/</link>
		<comments>http://just2us.com/2009/07/tutorial-obfuscate-an-android-application/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 17:57:54 +0000</pubDate>
		<dc:creator>samwize</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://just2us.com/2009/07/tutorial-obfuscate-an-android-application/</guid>
		<description><![CDATA[There is no easy way to obfuscate Java classes of an Android app. This is no Eclipse plugin, nor even a working ant script. Maybe there are working ant scripts. But for Android SDK 1.5, it seems like no one has supplied a proper one, yet. And hence, I spent half a day hacking out [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjust2us.com%2F2009%2F07%2Ftutorial-obfuscate-an-android-application%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjust2us.com%2F2009%2F07%2Ftutorial-obfuscate-an-android-application%2F&amp;source=samwize&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>There is no easy way to obfuscate Java classes of an Android app. This is no Eclipse plugin, nor even a working ant script.</p>
<p>Maybe there are <a href="http://code.google.com/p/zxing/source/browse/trunk/android-m3/build.xml?r=321">working ant scripts</a>. But for Android SDK 1.5, it seems like no one has supplied a proper one, yet. And hence, I spent half a day hacking out <a href="http://just2us.com/site/wp-content/uploads/2009/07/build.xml">a script that works</a>. There are more effort and hurdles than what are presented here.. but for a simple working script, here it is how I did it:</p>
<p>&#160;</p>
<h3>1 Create a Project</h3>
<p>From the Terminal, in /android-sdk/tools/, run:</p>
<blockquote><p>./android create project &#8211;target 2 &#8211;path /PATH/TO/ObfuscatedApp &#8211;activity MyActivity &#8211;package com.just2me.obfapp</p>
</blockquote>
<p>&#160;</p>
<h3>2 Edit build.xml</h3>
<p>Replace the build.xml with <a href="http://just2us.com/site/wp-content/uploads/2009/07/build.xml">my modified build.xml</a>, which is the most important item in this tutorial. The obfuscation work is in the optimize target as seen below.</p>
<p align="center"><a href="http://just2us.com/site/wp-content/uploads/2009/07/ant-buildxml.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="214" alt="ant build.xml" src="http://just2us.com/site/wp-content/uploads/2009/07/ant-buildxml-thumb.png" width="498" border="0" /></a> </p>
<p>Some points to note in the build.xml ant script:</p>
<ul>
<li>Edit the properties for the path to your Android SDK and <a href="http://proguard.sourceforge.net/">Proguard</a></li>
<li>If you use any libraries, copy them to /lib and add -libraryjars ${library-jar}/some_lib_used.jar accordingly </li>
<li>-dontoptimize is needed for Android</li>
<li>For all classes that are declared in AndroidManifest.xml Application nodes (Activities, Receviers, etc), add an arg to tell proguard not to obfuscate. Exampe: &quot;-keep public class com.just2me.obfapp.activity.*&quot; </li>
</ul>
<p>&#160;</p>
<h4>3 Run ant</h4>
<p>The last step is to simply run the ant script!</p>
<p>To package a debug version that is signed with a debug key, run &quot;ant debug-obf&quot;.</p>
<p>To package a release version that is unsigned, run &quot;ant release-obf&quot;.</p>
<p>If all is well, then you will find the products in /bin. ObfuscatedApp-debug.apk would be the debug package that could be installed on simulator/devices.</p>
]]></content:encoded>
			<wfw:commentRss>http://just2us.com/2009/07/tutorial-obfuscate-an-android-application/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to create multiple targets for Xcode iPhone Projects</title>
		<link>http://just2us.com/2009/07/tutorial-creating-multiple-targets-for-xcode-iphone-projects/</link>
		<comments>http://just2us.com/2009/07/tutorial-creating-multiple-targets-for-xcode-iphone-projects/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 14:09:03 +0000</pubDate>
		<dc:creator>samwize</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://just2us.com/2009/07/tutorial-creating-multiple-targets-for-xcode-iphone-projects/</guid>
		<description><![CDATA[If you want to build multiple versions of an application from a single Xcode project, you would want to cerate multiple targets. For example, when you want to release a free version and also a paid version, you should create 2 targets in that Xcode project. This tutorial will cover the how-to and the pitfalls [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjust2us.com%2F2009%2F07%2Ftutorial-creating-multiple-targets-for-xcode-iphone-projects%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjust2us.com%2F2009%2F07%2Ftutorial-creating-multiple-targets-for-xcode-iphone-projects%2F&amp;source=samwize&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>If you want to build multiple versions of an application from a single Xcode project, you would want to cerate multiple targets. For example, when you want to release a free version and also a paid version, you should create 2 targets in that Xcode project. </p>
<p>This tutorial will cover the how-to and the pitfalls in creating multiple targets.</p>
<p>&#160;</p>
<h4>1 Create a New Target</h4>
<p>Lets assume we have an application call &quot;Flowers&quot;, which is a paid version. And we would want to create a lite version that has some reduced functionality but is free. It is to note that both the paid version and lite version would share the same code, with only some differences.</p>
<p>Firstly, create a new target. Under Groups &amp; Files, right click on Targets &gt; Add &gt; New Target&#160; (Figure 1 below). </p>
<p align="center"><a href="http://just2us.com/site/wp-content/uploads/2009/07/picture-1.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="249" alt="Figure 1" src="http://just2us.com/site/wp-content/uploads/2009/07/picture-1-thumb.png" width="408" border="0" /></a> </p>
<p>Select Application as the new target template. </p>
<p>Enter &quot;FlowersLite&quot; as the target&#8217;s name.</p>
<p>Pitfall: When a new target is added, it would not copy over any resources, compiled sources or libraries from the original target! You would need to copy them over manually (drag and drop from Flowers to FlowersLite). If you copy all correctly, you would see figure 2 below. The numbers in brackets indicate number of files, hence they should be the same for both the targets.</p>
<p align="center"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="158" alt="Picture 5" src="http://just2us.com/site/wp-content/uploads/2009/07/picture-5-thumb.png" width="244" border="0" /> </p>
<p>&#160;</p>
<h4>2 Info.plist</h4>
<p>We could define properties, such as application name and icon files, for each of the target. Figure 3 below shows &quot;Flowers-Info.plist&quot; for the full version.</p>
<p align="center"><a href="http://just2us.com/site/wp-content/uploads/2009/07/picture-2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="226" alt="Picture 2" src="http://just2us.com/site/wp-content/uploads/2009/07/picture-2-thumb.png" width="560" border="0" /></a> </p>
<p>For the lite version, the &quot;FlowersLite-Info.plist&quot; could be changed as necessary. For example, the bundle identifier for the lite version could be &quot;com.just2me.flowerslite&quot; and the Icon file could be &quot;Icon-lite.png&quot; instead (as in figure 4 below).</p>
<p align="center"><a href="http://just2us.com/site/wp-content/uploads/2009/07/picture-3.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="174" alt="Picture 3" src="http://just2us.com/site/wp-content/uploads/2009/07/picture-3-thumb.png" width="542" border="0" /></a></p>
<p>&#160;</p>
<h4>3 Writing Preprocessor Codes</h4>
<p>Preprocessor codes are used to determine which code would be used during compile time. You may want different targets to run different section of the codes using preprocessor codes. For illustration, we will add a LITE_VERSION definition to the lite version. </p>
<p>Under Targets, right click FlowersLite &gt; Get Info.</p>
<p>Change Configuration to &quot;All Configurations&quot; (this is important).</p>
<p>In the Preprocessor Macros field, add the flag LITE_VERSION (see figure 5 below). Note: If you don&#8217;t see the section &quot;GCC 4.2 &#8211; Preprocessing&quot;, change the active SDK to base SDK and try again.</p>
<p align="center"><a href="http://just2us.com/site/wp-content/uploads/2009/07/picture-6.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="43" alt="Picture 6" src="http://just2us.com/site/wp-content/uploads/2009/07/picture-6-thumb.png" width="520" border="0" /></a> </p>
<p>With the flag LITE_VERSION defined, we could now write codes that will be compiled for the different targets. An example is shown in figure 6 below.</p>
<p align="center"><a href="http://just2us.com/site/wp-content/uploads/2009/07/picture-7.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="135" alt="Picture 7" src="http://just2us.com/site/wp-content/uploads/2009/07/picture-7-thumb.png" width="467" border="0" /></a></p>
<p>When the active target is selected and being run, it will work and print correctly.</p>
<p>&#160;</p>
<h3>4 Managing Resources</h3>
<p>You could copy different resources (having same name but different) to the targets. Resource could refer to xib files, images, etc. </p>
<p>For example, if the lite version has a different default loading screen, you could create another Default.png for the lite version. Note: To make it work, you have to copy the correct Default.png to that target&#8217;s &quot;Copy Bundle Resources&quot;, and also to remove the incorrect Default.png.</p>
<p>&#160;</p>
<h4>5 Build for Distribution</h4>
<p>When you are ready to compile the application for submission to iTunesconnect (release distribution), there is one last important thing worth checking.</p>
<p>It was pointed out in section 3 (Writing Preprocessor Code), that you have to change the configuration to &quot;All Configurations&quot; before you make any changes to the target properties (in this tutorial is adding the LITE_VERSION flag). That is important as the same flag is needed for all configurations, including distribution.</p>
<p>PS: I am stressing this last step as I had made this mistake.. and it resulted in my lite version being released as a paid version because the LITE_VERSION flag was only set for Debug, and not for Distribution!! I did not realize this mistake when compiling for Distribution, as I could only compile the app but not run it on simulator/device..</p>
]]></content:encoded>
			<wfw:commentRss>http://just2us.com/2009/07/tutorial-creating-multiple-targets-for-xcode-iphone-projects/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
