<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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" version="2.0">

<channel>
	<title>Scratch Pad</title>
	
	<link>http://www.uchidacoonga.com</link>
	<description>"Do it until it becomes boring, then keep doing it until it becomes beautiful."</description>
	<pubDate>Sat, 09 Jan 2010 05:10:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/uchidacoonga/feed" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="uchidacoonga/feed" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">uchidacoonga/feed</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Writing private methods in Objective-C</title>
		<link>http://www.uchidacoonga.com/?p=446</link>
		<comments>http://www.uchidacoonga.com/?p=446#comments</comments>
		<pubDate>Sat, 09 Jan 2010 05:09:25 +0000</pubDate>
		<dc:creator>yongrim</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[Objective-C]]></category>

		<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://www.uchidacoonga.com/?p=446</guid>
		<description><![CDATA[So there isn&#8217;t a real way to write private methods in Objective-C.
What I tried to for a while is to just write the methods in the .m file and simply omit the declarations in the .h file. This would be quite annoying when you call the private methods before they are defined in the .m [...]]]></description>
			<content:encoded><![CDATA[<p>So there isn&#8217;t a real way to write private methods in Objective-C.</p>
<p>What I tried to for a while is to just write the methods in the .m file and simply omit the declarations in the .h file. This would be quite annoying when you call the private methods before they are defined in the .m file because Xcode would give warnings.</p>
<p>One convention we&#8217;re using to deal with this is to define a (Private) category at the top of .m file containing all the declarations of the private methods. By doing this, you&#8217;re letting the compiler know that  about the &#8220;private&#8221; functions that these functions will exist, so the warnings go away. It&#8217;s also a nice way to communicate to the readers of your code that the methods are private. The (Private) category is defined inside the .m file, so it really remains, well, private.</p>
<p>Here is a real example from our Say a Secret project:</p>
<blockquote><p>#import &#8220;BadAssButtonController.h&#8221;<br />
#import &#8220;ButtonUtil.h&#8221;<br />
#import &#8220;Debug.h&#8221;</p>
<p>// Private methods</p>
<p><strong>@interface BadAssButtonController(Private)</strong></p>
<p><strong>-(void) doneAnimating_;</strong></p>
<p><strong>@end</p>
<p></strong></p>
<p>@implementation BadAssButtonController</p>
<p>@synthesize overlayImage;<br />
@synthesize button;<br />
&#8230; blah blah</p></blockquote>

<p><a href="http://feedads.g.doubleclick.net/~a/cis8N_zqRHUigCS2yGP6basdZPY/0/da"><img src="http://feedads.g.doubleclick.net/~a/cis8N_zqRHUigCS2yGP6basdZPY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/cis8N_zqRHUigCS2yGP6basdZPY/1/da"><img src="http://feedads.g.doubleclick.net/~a/cis8N_zqRHUigCS2yGP6basdZPY/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.uchidacoonga.com/?feed=rss2&amp;p=446</wfw:commentRss>
		</item>
		<item>
		<title>2010</title>
		<link>http://www.uchidacoonga.com/?p=440</link>
		<comments>http://www.uchidacoonga.com/?p=440#comments</comments>
		<pubDate>Sat, 09 Jan 2010 04:52:25 +0000</pubDate>
		<dc:creator>yongrim</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://www.uchidacoonga.com/?p=440</guid>
		<description><![CDATA[holy crap I just realized that 2 in binary is 010. 2 + 010 = 2010. Do you know what this means? It&#8217;s the end of the world of course.
Well, whatever surfing that I missed out on during the summer of 2009 because I was too busy cutting PNGs for Say a Secret &#8482;, I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>holy crap I just realized that 2 in binary is 010. 2 + 010 = 2010. Do you know what this means? It&#8217;s the end of the world of course.</p>
<p>Well, whatever surfing that I missed out on during the summer of 2009 because I was too busy cutting PNGs for Say a Secret &#8482;, I&#8217;m doing it these days. I&#8217;m actually going out to Pacifica tomorrow. There are swells coming in, and the conditions are supposed to be good. I&#8217;m feeling even better because I got home about 30 minutes ago and fixed a bug (that I created a few weeks ago which went unnoticed) without too much hassle. All thanks to a small bit of reading I did over the summer.</p>
<p>The book is Cocoa Programming for Mac OS X. This book is badass. It filled all the gap in my knowledge about Xcode, Cocoa, Objective C in one schbang. Thanks Aaron, you&#8217;re awesome. Chapter 1 even ends with a little motivational section on &#8220;How to Learn.&#8221;</p>
<p>Besides the general badassery of the book, I want to point out one of the strongest aspects, in my opinion of course, of this book - it is very hands-on. It doesn&#8217;t try to sugar-coat with dense jargon or make you feel itty-bitty by using theoretical mumbo jumbo. It even tells you *gasp* how to debug. And it was what I learned from this section of the book on how to debug that saved the day.</p>
<p>We&#8217;ve all seen it - the cryptic stack traces you see in Xcode when things foobar:</p>
<blockquote><p>2008-08-01 21:10:20.138 Tomatoes[151:20b] *** Terminating app due to uncaught exception ‘NSRangeException’, reason: ‘*** -[NSCFString replaceCharactersInRange:withString:]: Range or index out of bounds’<br />
2008-08-01 21:10:20.213 Foobar[151:20b] Stack: (<br />
808163835,<br />
806099672,<br />
807978623,<br />
807978527,<br />
812533155,<br />
812164939,<br />
812716685,<br />
22067,<br />
35325,<br />
812317455,<br />
812317325,<br />
824032771,<br />
824024301,<br />
824022997,<br />
807779567,<br />
807777675,<br />
829004012,<br />
816177936,<br />
816214500,<br />
8381,<br />
8244<br />
)<br />
terminate called after throwing an instance of ‘NSException’<br />
kill<br />
quit</p></blockquote>
<p>I&#8217;ve seen some tips on how to decode this stack trace using &#8216;atos&#8217; or whatnot. Guess what, I&#8217;m too lazy for that. I&#8217;d rather sprinkle NSLog statements than cut &amp; paste some numbers around.</p>
<p>News flash! There is an easier way folks!</p>
<p>Step 1: From the menu go to Run -&gt; Manage Breakpoints -&gt; Add Symbolic Breakpoint, and add &#8220;objc_exception_throw&#8221;. Now you&#8217;re all set - your Xcode is now badassified to automatically break whenever you write crappy code that throws an uncaught exception.</p>
<p>Step 2:  Write crappy code and make your code crash. C&#8217;mon, you know how to do this.</p>
<p>Step 3: Run your code - when it craps out, you&#8217;ll see the &#8216;(gdb)&#8217; prompt and your program has auto-suspended.</p>
<p>Step 4: Find that little spray can icon back in your Xcode IDE. It&#8217;s somewhere right above the editor.</p>
<p>Voila, now your see the stacktrace right in your IDE. No commandline incantation or nuttin. Now let&#8217;s go back to life &amp; surfing.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/Gdidx6Uy9DtbtQ5A39spuXrh7qU/0/da"><img src="http://feedads.g.doubleclick.net/~a/Gdidx6Uy9DtbtQ5A39spuXrh7qU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Gdidx6Uy9DtbtQ5A39spuXrh7qU/1/da"><img src="http://feedads.g.doubleclick.net/~a/Gdidx6Uy9DtbtQ5A39spuXrh7qU/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.uchidacoonga.com/?feed=rss2&amp;p=440</wfw:commentRss>
		</item>
		<item>
		<title>Intel X-25M G2 160 GB SSD</title>
		<link>http://www.uchidacoonga.com/?p=422</link>
		<comments>http://www.uchidacoonga.com/?p=422#comments</comments>
		<pubDate>Fri, 28 Aug 2009 21:22:20 +0000</pubDate>
		<dc:creator>Min</dc:creator>
		
		<category><![CDATA[Reviews]]></category>

		<category><![CDATA[160 GB]]></category>

		<category><![CDATA[Intel X25]]></category>

		<category><![CDATA[Intel X25-M G2]]></category>

		<category><![CDATA[Snow Leopard]]></category>

		<category><![CDATA[Solid State Disk]]></category>

		<category><![CDATA[Solid State Drive]]></category>

		<category><![CDATA[SSD]]></category>

		<guid isPermaLink="false">http://www.uchidacoonga.com/?p=422</guid>
		<description><![CDATA[Solid State Disks (SSD) are the future! I hereby declare that if you own equities in Western Digital, Seagate or any other platter based hard disk company, you better sell it quick because they are in trouble!
The hard disk market has been the last remaining bastion of &#8220;new old-tech&#8221; that has not seen true revolution [...]]]></description>
			<content:encoded><![CDATA[<p>Solid State Disks (SSD) are the future! I hereby declare that if you own equities in Western Digital, Seagate or any other platter based hard disk company, you better sell it quick because they are in trouble!</p>
<p>The hard disk market has been the last remaining bastion of &#8220;new old-tech&#8221; that has not seen true revolution since the dawn of modern computers. By far, it is the slowest and the least reliable part of a computer. When I buy a computer, I know that I will more than likely end up having to replace the hard drive.</p>
<p>My new technology obsession is the SSD. The price has come down to a point where a mortal enthusiast can afford one now for a mere price of a leg (not the two like it used to be). With Snow Leopard being released, I decided to take my new SSD for a spin. The undisputed king of SSDs at the moment is the Intel X-25M. The second generation (G2) came out not too long ago. With absolutely no moving parts, zero seek time and insane random read/write speeds, this thing just screams along. Here are some videos.</p>
<p>Please excuse the shaky camera work and the horrible video quality. I was using my left hand to record (I&#8217;m right handed) and the video is from an old, antiquated digital camera that&#8217;s just teetering on death.</p>
<p>For the first video. I went into the Applications folder, selected bunch of applications, and opened them up all at once at the same time. This is a new video I made with Quicktime X&#8217;s screen recording feature &#8212; new in Snow Leopard. I felt compelled to make a new presentable video after getting way too many complaints about the horrible quality of the first video.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/7F-dEMldRnI&#038;hl=en&#038;fs=1&#038;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/7F-dEMldRnI&#038;hl=en&#038;fs=1&#038;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>The second video shows me opening Adobe Photoshop, Illustrator and SoundBooth at once at the same time. If I had done this on a normal HDD, the HDD would have thrashed into tomorrow.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/r2IldwHay5k&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/r2IldwHay5k&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>The third video shows boot time from a completely shut down state. The timer starts as soon as I press the power button. The stop watch is hard to see due to the darkness and my crappy camera, but you can catch a glimpse of the final time towards the end of the video. For this video, I made a makeshift tripod out of my chair a coffee table after receiving complaints about motion sickness.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/sxD4RaL5kFc&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/sxD4RaL5kFc&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>The final two videos shows the boot up and program start up time from my old HDD. It&#8217;s painfully slow.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/butOCiLPV1U&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/butOCiLPV1U&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>Program start up video from a regular hard disk.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/x-n9AFJgQR8&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/x-n9AFJgQR8&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p><strong>I&#8217;m Sold!</strong><br />
After having only used this for a day, I can conclusively say that I don&#8217;t think I will ever go back to normal hard disks again. I believe that SSD is a revolutionary advancement in hard drive technology. When it comes to user interface performance, responsiveness (snappiness) and perception is everything. The number of IO operations per second this SSD can handle is impressive. It doesn&#8217;t matter what I throw at it, programs just load up in an instant.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/__Rf6qBK8hItTuVnOKEiG_il_js/0/da"><img src="http://feedads.g.doubleclick.net/~a/__Rf6qBK8hItTuVnOKEiG_il_js/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/__Rf6qBK8hItTuVnOKEiG_il_js/1/da"><img src="http://feedads.g.doubleclick.net/~a/__Rf6qBK8hItTuVnOKEiG_il_js/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.uchidacoonga.com/?feed=rss2&amp;p=422</wfw:commentRss>
		</item>
		<item>
		<title>Extremely Useful Debugging</title>
		<link>http://www.uchidacoonga.com/?p=416</link>
		<comments>http://www.uchidacoonga.com/?p=416#comments</comments>
		<pubDate>Wed, 26 Aug 2009 17:23:13 +0000</pubDate>
		<dc:creator>Min</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[Objective-C]]></category>

		<category><![CDATA[iPhone Development]]></category>

		<category><![CDATA[Crash]]></category>

		<category><![CDATA[Debug]]></category>

		<category><![CDATA[Debugging]]></category>

		<category><![CDATA[Iphone Debugging]]></category>

		<category><![CDATA[Stack]]></category>

		<category><![CDATA[Stack Trace]]></category>

		<guid isPermaLink="false">http://www.uchidacoonga.com/?p=416</guid>
		<description><![CDATA[More likely than not, your application will have crashed at some point in its development cycle. And you will have seen a cryptic message like this on the console.
2009-08-19 13:45:19.059 TestApp[3905:20b] Stack: (
2478641131,
2426342971,
2478670314,
2478663660,
2478663858,
92386,
816691521,
816216343,
816148479,
816144864,
827743722,
827753484,
2478142405,
2478144168,
827745792,
827745989,
816114848,
816160924,
9656,
9510
)
The problem is that you have no idea where in the code the crash is happening. Java&#8217;s stack trace is very descriptive, with [...]]]></description>
			<content:encoded><![CDATA[<p>More likely than not, your application will have crashed at some point in its development cycle. And you will have seen a cryptic message like this on the console.</p>
<pre>2009-08-19 13:45:19.059 TestApp[3905:20b] Stack: (
2478641131,
2426342971,
2478670314,
2478663660,
2478663858,
92386,
816691521,
816216343,
816148479,
816144864,
827743722,
827753484,
2478142405,
2478144168,
827745792,
827745989,
816114848,
816160924,
9656,
9510
)</pre>
<p>The problem is that you have no idea where in the code the crash is happening. Java&#8217;s stack trace is very descriptive, with function names and line numbers. This is also possible in XCode, but you have to take an extra step.</p>
<p>Run your iPhone application and then wait for it to crash, displaying the stack trace as above. The program will have paused at this point. If you go down to the console, you&#8217;ll see a prompt that says (gdb), where you can type in gdb commands.</p>
<p>Look at the stack trace above, and try to find a small number somewhere in the middle of the stack. This is likely where your program crashed. In the example above, this number is 92386. Once you have identified this number, you can now identify more helpful information about the crash.</p>
<p>Issuing the command: info symbol 92386</p>
<p>Will give you something like this:<code><br />
<span style="color: #ff0000;">-[MainViewController touchesEnded:withEvent:] + 164 in section LC_SEGMENT.__TEXT.__text of /Users/Min/Library/Application Support/iPhone Simulator/User/Applications/877EB45A-AB6B-4CD5-AA43-C7B0F2C98F7B/TestApp.app/TestApp</span></code></p>
<p>Issuing the command: info line *92386<br />
Will you give something like this:<br />
<code><br />
<span style="color: #ff0000;">Line 416 of &#8220;/Users/Min/Documents/Projects/TestApp/Classes/MainViewController.m&#8221; starts at address 0&#215;168b5 &lt;-[MainViewController touchesEnded:withEvent:]+119&gt; and ends at 0&#215;16985 &lt;-[MainViewController touchesEnded:withEvent:]+327&gt;</span><br />
</code></p>
<p>So there you have it. You now know that the crash took place in the [MainViewController touchedEnd:withEvent:] message on line 416.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/YbfRjLqFEMUFlvDLXPzzo-J7Wwk/0/da"><img src="http://feedads.g.doubleclick.net/~a/YbfRjLqFEMUFlvDLXPzzo-J7Wwk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/YbfRjLqFEMUFlvDLXPzzo-J7Wwk/1/da"><img src="http://feedads.g.doubleclick.net/~a/YbfRjLqFEMUFlvDLXPzzo-J7Wwk/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.uchidacoonga.com/?feed=rss2&amp;p=416</wfw:commentRss>
		</item>
		<item>
		<title>Threads and Waiting</title>
		<link>http://www.uchidacoonga.com/?p=392</link>
		<comments>http://www.uchidacoonga.com/?p=392#comments</comments>
		<pubDate>Mon, 24 Aug 2009 20:59:40 +0000</pubDate>
		<dc:creator>Min</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[Objective-C]]></category>

		<category><![CDATA[iPhone Development]]></category>

		<category><![CDATA[Busy Loop]]></category>

		<category><![CDATA[iPhone]]></category>

		<category><![CDATA[Multithreading]]></category>

		<category><![CDATA[NSConditionLock]]></category>

		<category><![CDATA[NSThread]]></category>

		<category><![CDATA[Polling]]></category>

		<category><![CDATA[Threading]]></category>

		<category><![CDATA[Waiting]]></category>

		<guid isPermaLink="false">http://www.uchidacoonga.com/?p=392</guid>
		<description><![CDATA[Proper use of threads will do wonders for your program&#8217;s responsiveness. It will also do wonders in making your code harder to follow. What if you have a thread churning along in the background and you&#8217;d like to know when that thread has produced a value before continuing on with your work? Maybe you have [...]]]></description>
			<content:encoded><![CDATA[<p>Proper use of threads will do wonders for your program&#8217;s responsiveness. It will also do wonders in making your code harder to follow. What if you have a thread churning along in the background and you&#8217;d like to know when that thread has produced a value before continuing on with your work? Maybe you have a thread called ComputeWinningStockThread that takes all the data from the stock market, applies some magic formula and spits out stocks that are going to make you millions in random time intervals.</p>
<p>1. Start ComputeWinningStockThread in background.<br />
2. Until ComputeWinningStockThread has picked a stock, continue checking to see if it has.</p>
<p>This is the poor man&#8217;s version. It is also called the busy loop or polling. And it uses up valuable resources that your iPhone could be using for other things.</p>
<p>The proper way to handle this is with the NSConditionLock. You can use NSConditionLock to have one thread wait for notification from another thread before continuing. Or, in other words, it blocks until a condition is met (hence, the name conditional lock).</p>
<p>In Objective-C, this is the gist of what you would have to do.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> ComputeWinningStockThread <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">while</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>myLock lock<span style="color: #002200;">&#93;</span>;
        winningStock <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self someSecretAlgorithm<span style="color: #002200;">&#93;</span>;        
        <span style="color: #002200;">&#91;</span>myLock unlockWithCondition<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Then maybe in another message, you are calling this thread to earn your millions.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSConditionLock</span> <span style="color: #002200;">*</span>myLock <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSConditionLock</span> alloc<span style="color: #002200;">&#93;</span> initWithCondition<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span><span style="color: #400080;">NSThread</span> detachNewThreadSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>ComputeWinningStockThread<span style="color: #002200;">&#41;</span> toTarget<span style="color: #002200;">:</span>self withObject<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// This will block until it is unlocked in the thread</span>
<span style="color: #002200;">&#91;</span>myLock lockWhenCondition<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;I have a winning stock! %@&quot;</span>, winningStock<span style="color: #002200;">&#41;</span>;</pre></td></tr></table></div>


<p><a href="http://feedads.g.doubleclick.net/~a/IjmJN29fJCmAeXWSGt2KHQm9NGM/0/da"><img src="http://feedads.g.doubleclick.net/~a/IjmJN29fJCmAeXWSGt2KHQm9NGM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/IjmJN29fJCmAeXWSGt2KHQm9NGM/1/da"><img src="http://feedads.g.doubleclick.net/~a/IjmJN29fJCmAeXWSGt2KHQm9NGM/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.uchidacoonga.com/?feed=rss2&amp;p=392</wfw:commentRss>
		</item>
		<item>
		<title>Handling didReceiveMemoryWarning</title>
		<link>http://www.uchidacoonga.com/?p=383</link>
		<comments>http://www.uchidacoonga.com/?p=383#comments</comments>
		<pubDate>Fri, 21 Aug 2009 04:22:11 +0000</pubDate>
		<dc:creator>Min</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[Objective-C]]></category>

		<category><![CDATA[iPhone Development]]></category>

		<category><![CDATA[didReceiveMemoryWarning]]></category>

		<category><![CDATA[iPhone memory leak]]></category>

		<category><![CDATA[Low Memory]]></category>

		<category><![CDATA[safari]]></category>

		<category><![CDATA[setView]]></category>

		<guid isPermaLink="false">http://www.uchidacoonga.com/?p=383</guid>
		<description><![CDATA[Predicting user behavior on the iPhone is difficult. One can never know how many pages of Safari someone might have in the background hogging up valuable resources. Every now and then, I get reports of our application crashing for no apparent reason. More often than not, it&#8217;s caused by the phone running low on memory. [...]]]></description>
			<content:encoded><![CDATA[<p>Predicting user behavior on the iPhone is difficult. One can never know how many pages of Safari someone might have in the background hogging up valuable resources. Every now and then, I get reports of our application crashing for no apparent reason. More often than not, it&#8217;s caused by the phone running low on memory. It&#8217;s amazing how little memory we have to work with on the iPhone. With Safari taking up 8 pages in the background, our application was crashing at mere 8 MB of memory usage.</p>
<p><strong>Load Late and Lazily</strong></p>
<p>Sometimes you have to sacrifice the snappy UI for a low memory footprint. It&#8217;s better than your application crashing. This means never preloading resources but waiting until the moment you need it. If your XIB (NIB) file has a lot of views, try separating them into multiple NIB files so that you can load it individually when you need it. When a view is not visible, the system will free it from memory.</p>
<p><strong>- (void) didReceiveMemoryWarning</strong></p>
<p>The didReceiveMemoryWarning message will be called when the iPhone is running load on memory. It is highly recommended that you override this message in all your view controllers and print out a simple debug message in it. Also, do not forget to call [super didReceiveMemoryWarning].</p>
<p><strong>- (void) setView:(UIView*) view</strong></p>
<p>If you receive the didReceiveMemoryWarning message, the setView message will be called with a nil parameter. It will be called to release the view if the view is not the active view. This is where you will want to release as much resources as you can, such as all your IBOutlet variables. Also, do not forget to call [super setView:view] or your application will crash.</p>
<p><strong>Initialization</strong></p>
<p>Once your view is freed, the NIB will be read back into memory when it is needed. This means the viewDidLoad message will be called again. So take care not to place initialization code that should only be initialized once per application in that message.</p>
<p><strong>CLANG Analyzer</strong></p>
<p>If you haven&#8217;t tried this tool already, then you are truly missing out. Check out this <a href="http://iphonedevelopment.blogspot.com/2009/02/clang-static-analyzer.html">extremely helpful post</a> by Jeff Lamarche, the author of Beginning iPhone Development. CLANG will analyze your code and give you a detailed report of problems your code may have, including memory leaks.</p>
<p>Also, If you&#8217;ve missed my previous post about the dangers of UIImage, you can check it out <a href="http://www.uchidacoonga.com/?p=340">here.</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/SokyAWauV1K2YpPDNbcdOoZ9fu0/0/da"><img src="http://feedads.g.doubleclick.net/~a/SokyAWauV1K2YpPDNbcdOoZ9fu0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/SokyAWauV1K2YpPDNbcdOoZ9fu0/1/da"><img src="http://feedads.g.doubleclick.net/~a/SokyAWauV1K2YpPDNbcdOoZ9fu0/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.uchidacoonga.com/?feed=rss2&amp;p=383</wfw:commentRss>
		</item>
		<item>
		<title>Memory Management Pitfalls</title>
		<link>http://www.uchidacoonga.com/?p=372</link>
		<comments>http://www.uchidacoonga.com/?p=372#comments</comments>
		<pubDate>Thu, 21 May 2009 16:50:42 +0000</pubDate>
		<dc:creator>Min</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[Objective-C]]></category>

		<category><![CDATA[iPhone Development]]></category>

		<category><![CDATA[Alloc]]></category>

		<category><![CDATA[iPhone]]></category>

		<category><![CDATA[memory management]]></category>

		<category><![CDATA[Memory Pitfalls]]></category>

		<category><![CDATA[Release]]></category>

		<category><![CDATA[Retain]]></category>

		<guid isPermaLink="false">http://www.uchidacoonga.com/?p=372</guid>
		<description><![CDATA[I thought that, for the most part, I was done with memory management after moving on from C/C++ to Java. But we all know that was not to be, so I&#8217;ve created this quick reference sheet for my own reference that some of you may find useful.
Pitfall 1: The order matters
Assume we have a setter [...]]]></description>
			<content:encoded><![CDATA[<p>I thought that, for the most part, I was done with memory management after moving on from C/C++ to Java. But we all know that was not to be, so I&#8217;ve created this quick reference sheet for my own reference that some of you may find useful.</p>
<p><strong>Pitfall 1: The order matters</strong><br />
Assume we have a setter method in some class.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> setText<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>newValue
<span style="color: #002200;">&#123;</span>
   <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>newValue <span style="color: #002200;">!=</span> text<span style="color: #002200;">&#41;</span>
   <span style="color: #002200;">&#123;</span>
      <span style="color: #002200;">&#91;</span>newValue retain<span style="color: #002200;">&#93;</span>;
      <span style="color: #002200;">&#91;</span>text release<span style="color: #002200;">&#93;</span>;
      text <span style="color: #002200;">=</span> newValue;
   <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>The <em>NSString</em> that is passed into <em>setText</em> may be another <em>NSString</em>. So the value that is passed in must be retained, because we can&#8217;t have the memory freed until we are done with the class. We release <em>text</em> because it is being repaced with <em>newValue</em>.</p>
<p>Note that it is wrong the write the code above as</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> setText<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>newValue
<span style="color: #002200;">&#123;</span>
      <span style="color: #002200;">&#91;</span>text release<span style="color: #002200;">&#93;</span>;
      <span style="color: #002200;">&#91;</span>newValue retain<span style="color: #002200;">&#93;</span>;
      text <span style="color: #002200;">=</span> newValue;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>This is a due to a somewhat subtle case when <em>text </em> and <em>newValue</em> points to the same instance of <em>NSString</em>. By releasing <em>text</em>, <em>newValue</em> will also be released.</p>
<p><strong>Pitfall 2: Using the dot (&#8217;.') notation incorrectly</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">self.text <span style="color: #002200;">=</span> newText</pre></div></div>

<p>is actually a shorthand form of</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>self setText<span style="color: #002200;">:</span> newText<span style="color: #002200;">&#93;</span></pre></div></div>

<p>Thus, it will retain <em>newText</em>, increasing the reference count. Do not confuse it with how it works in a language like Java.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">this.text <span style="color: #002200;">=</span> newText</pre></div></div>

<p>is different from</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">self.text <span style="color: #002200;">=</span> newText</pre></div></div>

<p>Because the first is a direct assignment and the second is actually a message call.</p>
<p><strong>Pitfall 3: Not following the fundamental rules of reference counting</strong><br />
The fundamental rules are:<br />
1. If you allocate, create or copy it, you need to release it.<br />
2. If you retain it, you need to release it.</p>
<p>Consider the following snippet of code</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">SomeObject <span style="color: #002200;">*</span>newObject <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>SomeObject alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
self.object <span style="color: #002200;">=</span> newObject;
<span style="color: #002200;">&#91;</span>newObject release<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p><em>newObject</em> needs to be released to balance the retains. The first retain is in the <em>alloc</em> call, and the second retain is in the <em>setObject (aka self.object = newObject)</em> message.</p>
<p>Also, if you write something like this</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">self.object <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>SomeObject alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>the retain count will be at 2 because it is retained once for the <em>alloc</em> and one more time for the <em>setObject</em> message.</p>
<p>If you&#8217;d like to read more about memory management, <a href="http://www.uchidacoonga.com/?p=95">here</a> is another post that I wrote about the topic (I also talk about <em>NSAutoReleasePool</em> a bit here).</p>
<p>This wasn&#8217;t a comprehensive overview of memory management, but I hope it was somewhat helpful.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/4xZ5UmtwL9zfDQY69uRpNDPiK6k/0/da"><img src="http://feedads.g.doubleclick.net/~a/4xZ5UmtwL9zfDQY69uRpNDPiK6k/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/4xZ5UmtwL9zfDQY69uRpNDPiK6k/1/da"><img src="http://feedads.g.doubleclick.net/~a/4xZ5UmtwL9zfDQY69uRpNDPiK6k/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.uchidacoonga.com/?feed=rss2&amp;p=372</wfw:commentRss>
		</item>
		<item>
		<title>Tale of Search Woes</title>
		<link>http://www.uchidacoonga.com/?p=370</link>
		<comments>http://www.uchidacoonga.com/?p=370#comments</comments>
		<pubDate>Thu, 07 May 2009 21:29:22 +0000</pubDate>
		<dc:creator>Min</dc:creator>
		
		<category><![CDATA[News and Updates]]></category>

		<category><![CDATA[Opinion]]></category>

		<category><![CDATA[Apple Confidential Algorithm]]></category>

		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.uchidacoonga.com/?p=370</guid>
		<description><![CDATA[I don&#8217;t know what has been going on (actually, I do), but we have been seeing a statistically significant increase in the sales of iHappyBirthday. It wasn&#8217;t too long ago that we noticed that our application would not appear in the search results if the search terms were &#8220;happy birthday&#8221;, though it was still search-able [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know what has been going on (actually, I do), but we have been seeing a statistically significant increase in the sales of iHappyBirthday. It wasn&#8217;t too long ago that we noticed that our application would not appear in the search results if the search terms were &#8220;happy birthday&#8221;, though it was still search-able with the term &#8220;birthday&#8221;. It was odd because it has always been search-able by &#8220;happy birthday.&#8221;</p>
<p>We emailed Apple about it, and the response we got back was pure hilarity.</p>
<blockquote><p><span style="border-collapse: separate; color: #000000; font-family: 'Lucida Sans'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span style="border-collapse: separate; color: #000000; font-family: 'Lucida Sans'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">Search results are working as expected at this time. App Store search results are based on several factors determined by Apple-confidential algorithms.</span></span></p></blockquote>
<p>I&#8217;m not sure what this super secret &#8220;Apple-confidential algorithms&#8221; were that made it unsearchable by &#8220;happy birthday&#8221;, but it at least it did make us laugh. It was most likely a canned response because search was actually broken.</p>
<p>Anyways, we didn&#8217;t realize how important it was for our application to be search-able by &#8220;happy birthday&#8221;, because as soon as search was fixed, our sales have doubled (albeit from a small number, but welcome none the less!).</p>

<p><a href="http://feedads.g.doubleclick.net/~a/ZnULbZ9T3D2MJeyYhxQ21c9epKQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/ZnULbZ9T3D2MJeyYhxQ21c9epKQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ZnULbZ9T3D2MJeyYhxQ21c9epKQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/ZnULbZ9T3D2MJeyYhxQ21c9epKQ/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.uchidacoonga.com/?feed=rss2&amp;p=370</wfw:commentRss>
		</item>
		<item>
		<title>Back from the Dead</title>
		<link>http://www.uchidacoonga.com/?p=365</link>
		<comments>http://www.uchidacoonga.com/?p=365#comments</comments>
		<pubDate>Fri, 24 Apr 2009 17:07:56 +0000</pubDate>
		<dc:creator>Min</dc:creator>
		
		<category><![CDATA[News and Updates]]></category>

		<category><![CDATA[iPhone]]></category>

		<category><![CDATA[SaS]]></category>

		<guid isPermaLink="false">http://www.uchidacoonga.com/?p=365</guid>
		<description><![CDATA[It&#8217;s been very quiet here. Life has once again conspired to get in the way of our goals and dreams. My full time job has been keeping me busy at 70 hours a week. As much as I wanted to work on my iPhone project, I do enjoy what I do for a living, and [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been very quiet here. Life has once again conspired to get in the way of our goals and dreams. My full time job has been keeping me busy at 70 hours a week. As much as I wanted to work on my iPhone project, I do enjoy what I do for a living, and one of my long term goals in life is to foster my career. Actually, allow me to impart some wisdom in light of the current economic crisis. I actually believe that investing in your career and education is the best investment that you can make (and not in retirement accounts, though it&#8217;s a good idea). I recently had my midterm as well, so that also kept me away from working on our second application.</p>
<p>The schedule is starting to regain some semblance of sanity, so I will be able to devote more time to the iPhone project once again. The lack of time is only part of the reason for the delay, however. We decided to totally abandon the current design and go for something more innovative and creative. I&#8217;m not actually sure how well it will be received, but we noticed that there are too many of the same old and tired interface designs on thousands of applications. Though our application might be interesting, we felt that the interface design may hold us back. So a paradigm shift in our thinking and a total overhaul of the interface was required in order to stand out from the crowd.</p>
<p>Wish us luck!</p>

<p><a href="http://feedads.g.doubleclick.net/~a/Ga6q9ODE_BNH0P249Sup3Yd7zo4/0/da"><img src="http://feedads.g.doubleclick.net/~a/Ga6q9ODE_BNH0P249Sup3Yd7zo4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Ga6q9ODE_BNH0P249Sup3Yd7zo4/1/da"><img src="http://feedads.g.doubleclick.net/~a/Ga6q9ODE_BNH0P249Sup3Yd7zo4/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.uchidacoonga.com/?feed=rss2&amp;p=365</wfw:commentRss>
		</item>
		<item>
		<title>The Free Model</title>
		<link>http://www.uchidacoonga.com/?p=348</link>
		<comments>http://www.uchidacoonga.com/?p=348#comments</comments>
		<pubDate>Fri, 27 Feb 2009 13:52:09 +0000</pubDate>
		<dc:creator>Min</dc:creator>
		
		<category><![CDATA[News and Updates]]></category>

		<category><![CDATA[Opinion]]></category>

		<category><![CDATA[Bad Driver]]></category>

		<category><![CDATA[Blind Spot]]></category>

		<category><![CDATA[Car Accident]]></category>

		<category><![CDATA[Free Model]]></category>

		<category><![CDATA[iHappyBirthday Lite]]></category>

		<category><![CDATA[Lite]]></category>

		<category><![CDATA[Rant]]></category>

		<guid isPermaLink="false">http://www.uchidacoonga.com/?p=348</guid>
		<description><![CDATA[We&#8217;ve received a couple of negative reviews due to the application crashing (which I explained in my previous post). I guess you can&#8217;t help that. But the good news is that we haven&#8217;t really heard of any more reports of it crashing after version 1.1.1 was published.
A couple of days ago, the Lite version of [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve received a couple of negative reviews due to the application crashing (which I explained in my previous post). I guess you can&#8217;t help that. But the good news is that we haven&#8217;t really heard of any more reports of it crashing after version 1.1.1 was published.</p>
<p>A couple of days ago, the Lite version of iHappyBirthday was released to the App store. Imagine my surprise when I checked the sales figure this morning and saw that it was downloaded close to 600 times. Only if the same were true of the paid version! I think we need to observe it a bit more to see what kind of effect the Lite version will have, but as of yet, it has had no effect. Hey, at least it didn&#8217;t have a negative effect!</p>
<p>We&#8217;re trying to implement one, last key feature to SaS before we release it to the general public. But it&#8217;s turning out to be a bit of a technical challenge. Hopefully it won&#8217;t hold us up for too long!</p>
<p><strong>Edit</strong>: Oops. I miscalculated. It was downloaded close to 1000 times.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/qig1qzmBkGz5YZF14doB1bcLbIQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/qig1qzmBkGz5YZF14doB1bcLbIQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/qig1qzmBkGz5YZF14doB1bcLbIQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/qig1qzmBkGz5YZF14doB1bcLbIQ/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.uchidacoonga.com/?feed=rss2&amp;p=348</wfw:commentRss>
		</item>
	</channel>
</rss>
