<?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>Raymond Law &#187; iPhone</title>
	<atom:link href="http://rayvinly.com/articles/category/iphone/feed/" rel="self" type="application/rss+xml" />
	<link>http://rayvinly.com</link>
	<description>Badminton on Rails</description>
	<lastBuildDate>Fri, 04 May 2012 12:30:20 +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>ARC Conversions Explained &#8211; Part 3 of 3</title>
		<link>http://rayvinly.com/articles/2012/05/02/arc-conversions-explained-part-3-of-3/</link>
		<comments>http://rayvinly.com/articles/2012/05/02/arc-conversions-explained-part-3-of-3/#comments</comments>
		<pubDate>Wed, 02 May 2012 09:00:11 +0000</pubDate>
		<dc:creator>Raymond Law</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[ARC]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://rayvinly.com/?p=222</guid>
		<description><![CDATA[In Part 2, I talked about the removal of retain, release, and autorelease. The ARC conversion tool also removes: - &#40;void&#41;dealloc &#123; &#91;super dealloc&#93;; &#125; Since ARC handles memory management for us, we no longer need to explicitly call release. Since most of the time the dealloc method is used to release memory. The dealloc [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://rayvinly.com/articles/2012/04/25/arc-conversions-explained-part-2-of-3/" target="_blank">Part 2</a>, I talked about the removal of <em>retain</em>, <em>release</em>, and <em>autorelease</em>. The <span class="caps">ARC </span>conversion tool also removes:</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>dealloc
<span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>




<p>Since <span class="caps">ARC </span>handles memory management for us, we no longer need to explicitly call <em>release</em>. Since most of the time the <em>dealloc</em> method is used to release memory. The <em>dealloc</em> method can be removed. The chaining to <em>super</em> is automated and enforced by the compiler.</p>

<h3>Toll-Free Bridging</h3>

<p>Toll-Free Bridging means you can cast an object between Objective-C and Core Foundation freely, as long as you call <em>retain</em> and <em>release/autorelease</em> properly.However, with <span class="caps">ARC </span>doing memory management for us, we do not call these methods directly. Therefore, when we cast an object between Objective-C and Core Foundation, we need to tell <span class="caps">ARC </span>what to do when the object is no longer needed.</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">__bridge
__bridge_transfer   CFBridgingRelease
__bridge_retained   CFBridgingRetain    CFRelease</pre></div></div>




<ul>
  <li>When changing ownership from Core Foundation to Objective-C, you use <span class="caps">CFB</span>ridgingRelease().</li>
  <li>When changing ownership from Objective-C to Core Foundation, you use <span class="caps">CFB</span>ridgingRetain().</li>
  <li>When you want to use one type temporarily as if it were another without ownership change, you use __bridge.</li>
</ul><div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/rayvinly?i=http://rayvinly.com/articles/2012/05/02/arc-conversions-explained-part-3-of-3/" type="text/javascript" charset="utf-8"></script></div>]]></content:encoded>
			<wfw:commentRss>http://rayvinly.com/articles/2012/05/02/arc-conversions-explained-part-3-of-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ARC Conversions Explained &#8211; Part 2 of 3</title>
		<link>http://rayvinly.com/articles/2012/04/25/arc-conversions-explained-part-2-of-3/</link>
		<comments>http://rayvinly.com/articles/2012/04/25/arc-conversions-explained-part-2-of-3/#comments</comments>
		<pubDate>Wed, 25 Apr 2012 09:00:18 +0000</pubDate>
		<dc:creator>Raymond Law</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[ARC]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://rayvinly.com/?p=220</guid>
		<description><![CDATA[In Part 1, I mentioned that ARC allows us to focus on application code rather than thinking about having to call retain, release, and autorelease. ARC makes the following changes: cell = &#91;&#91;&#91;UITableViewCell alloc&#93; initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier&#93; autorelease&#93;; &#160; cell = &#91;&#91;UITableViewCell alloc&#93; initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier&#93;; In a project, there is the default autorelease pool that gets [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://rayvinly.com/articles/2012/04/18/arc-conversions-explained-part-1-of-3/" target="_blank">Part 1</a>, I mentioned that <span class="caps">ARC </span>allows us to focus on application code rather than thinking about having to call <em>retain</em>, <em>release</em>, and <em>autorelease</em>. <span class="caps">ARC </span>makes the following changes:</p>


<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">cell = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#91;</span>UITableViewCell alloc<span style="color:#006600; font-weight:bold;">&#93;</span> initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier<span style="color:#006600; font-weight:bold;">&#93;</span> autorelease<span style="color:#006600; font-weight:bold;">&#93;</span>;
&nbsp;
cell = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#91;</span>UITableViewCell alloc<span style="color:#006600; font-weight:bold;">&#93;</span> initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier<span style="color:#006600; font-weight:bold;">&#93;</span>;</pre></div></div>




<p>In a project, there is the default autorelease pool that gets created in <strong>main.m</strong>:</p>


<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">int main<span style="color:#006600; font-weight:bold;">&#40;</span>int argc, char <span style="color:#006600; font-weight:bold;">*</span>argv<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
    NSAutoreleasePool <span style="color:#006600; font-weight:bold;">*</span> pool = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#91;</span>NSAutoreleasePool alloc<span style="color:#006600; font-weight:bold;">&#93;</span> init<span style="color:#006600; font-weight:bold;">&#93;</span>;
    int retVal = UIApplicationMain<span style="color:#006600; font-weight:bold;">&#40;</span>argc, argv, <span style="color:#0000FF; font-weight:bold;">nil</span>, <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>;
    <span style="color:#006600; font-weight:bold;">&#91;</span>pool release<span style="color:#006600; font-weight:bold;">&#93;</span>;
    <span style="color:#0000FF; font-weight:bold;">return</span> retVal;
<span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>




<p>Your application is called to work with the call to <em><span class="caps">UIA</span>pplicationMain</em>:</p>


<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">int retVal = UIApplicationMain<span style="color:#006600; font-weight:bold;">&#40;</span>argc, argv, <span style="color:#0000FF; font-weight:bold;">nil</span>, <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</pre></div></div>




<p>The return value of the running of your application is used as the return value of the main function. This makes sense.</p>

<p>What about the lines regarding the pool? It turns out that objects created in the code between the creation and destruction of the <span class="caps">NSA</span>utoreleasePool will use that wrapping <em><span class="caps">NSA</span>utoreleasePool</em> to auto-release objects when they are no longer needed. You do this by calling the autorelease method on the object. Since <span class="caps">ARC </span>handles memory management for us, we don&#8217;t need to autorelease objects anymore. Therefore, taking out the call to autorelease will just do the trick here.</p>

<p>The same thing goes for retain and release. The <span class="caps">ARC </span>conversion tool suggests removing:</p>


<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&#91;</span>label release<span style="color:#006600; font-weight:bold;">&#93;</span>;</pre></div></div>




<p>When we specified our property, we changed it from <em>retain</em> to <em>strong</em> to indicate that we intend to use the property as a strong pointer, but we do not increment its reference count. To balance things out, we do not decrement its reference count either. Therefore, the call to <em>release</em> is not needed.</p>

<p>In fact, <span class="caps">ARC </span>would not even compile if it sees that you call <em>retain</em>, <em>release</em>, or <em>autorelease</em>. You will never forget to take this out if you are using <span class="caps">ARC.</span></p>

<h3><span class="caps">TIP </span>#1:</h3>

<p>Almost every project creates its default <em><span class="caps">NSA</span>utoreleasePool</em> in <em>main.m</em>, but you can also create your own <em><span class="caps">NSA</span>utoreleasePool</em> if necessary. I&#8217;ve never had to do this, so I can&#8217;t say I am an expert. I will just point to the <em><span class="caps">NSA</span>utoreleasePool</em> class reference which describes when and how you should do this. Specifically, it says:</p>

<p>The Application Kit creates an autorelease pool on the main thread at the beginning of every cycle of the event loop, and drains it at the end, thereby releasing any autoreleased objects generated while processing an event. If you use the Application Kit, you therefore typically don&#8217;t have to create your own pools. If your application creates a lot of temporary autoreleased objects within the event loop, however, it may be beneficial to create &#8220;local&#8221; autorelease pools to help to minimize the peak memory footprint.</p>

<p>It&#8217;s good to know that the option is there if you application uses a lot of memory and you need to deal with it in a more effective manner. I brought this up because the syntax of using an <em><span class="caps">NSA</span>utoreleasePool</em> has changed from:</p>


<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">int main<span style="color:#006600; font-weight:bold;">&#40;</span>int argc, char <span style="color:#006600; font-weight:bold;">*</span>argv<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
    NSAutoreleasePool<span style="color:#006600; font-weight:bold;">*</span> pool = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#91;</span>NSAutoreleasePool alloc<span style="color:#006600; font-weight:bold;">&#93;</span> init<span style="color:#006600; font-weight:bold;">&#93;</span>;
    int retVal = UIApplicationMain<span style="color:#006600; font-weight:bold;">&#40;</span>argc, argv, <span style="color:#0000FF; font-weight:bold;">nil</span>, <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>;
    <span style="color:#006600; font-weight:bold;">&#91;</span>pool release<span style="color:#006600; font-weight:bold;">&#93;</span>;
    <span style="color:#0000FF; font-weight:bold;">return</span> retVal;
<span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>




<p>to:</p>


<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">int main<span style="color:#006600; font-weight:bold;">&#40;</span>int argc, char <span style="color:#006600; font-weight:bold;">*</span>argv<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#0066ff; font-weight:bold;">@autoreleasepool</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
        int retVal = UIApplicationMain<span style="color:#006600; font-weight:bold;">&#40;</span>argc, argv, <span style="color:#0000FF; font-weight:bold;">nil</span>, NSStringFromClass<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>AppDelegate <span style="color:#9966CC; font-weight:bold;">class</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;
        <span style="color:#0000FF; font-weight:bold;">return</span> retVal;
    <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>




<p>The alloc-init-release has been replaced by <em>@autoreleasepool { &#8230; }</em>.</p>

<h3><span class="caps">TIP </span>#2:</h3>

<p>The above snippet also shows another subtle difference between a project created in Xcode 4.2 and previous versions.</p>

<p>The <em>AppDelegate</em> inherits from <em><span class="caps">NSO</span>bject</em> in older Xcode, but it now inherits from <em><span class="caps">UIR</span>esponder</em> in Xcode 4.2.</p>


<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#0066ff; font-weight:bold;">@interface</span> AppDelegate : NSObject <span style="color:#006600; font-weight:bold;">&lt;</span>UIApplicationDelegate<span style="color:#006600; font-weight:bold;">&gt;</span>
&nbsp;
<span style="color:#0066ff; font-weight:bold;">@interface</span> AppDelegate : UIResponder <span style="color:#006600; font-weight:bold;">&lt;</span>UIApplicationDelegate<span style="color:#006600; font-weight:bold;">&gt;</span></pre></div></div>




<p>When you create a new project in Xcode 4.2, the <em>AppDelegate</em> inherits from <em><span class="caps">UIR</span>esponder</em> instead of <em><span class="caps">NSO</span>bject</em>. This is necessary if you check the box that says Use Storyboard, which is another new Xcode feature that makes your application flow clearer to help you developing your application. Inheriting from <em><span class="caps">UIR</span>esponder</em> makes the <em>AppDelegate</em> eligible to respond to events.</p>

<p>Converting to <a href="http://bitly.com/HJcoyu" target="_blank">Storyboards Release Notes</a> says:</p>

<blockquote>The application delegate is responsible for loading the storyboard and managing the window. You need to specify the name of the application delegate class in <em><span class="caps">UIA</span>pplicationMain</em>, and ensure that the application delegate has a property called window.
</blockquote>

<p>If you use Storyboard, make sure your <em>AppDelegate</em> does that, and pass the class name of <em>AppDelegate</em> to <em><span class="caps">UIA</span>pplicationMain</em>. If you are using individual Xibs, you can still inherit from <em><span class="caps">NSO</span>bject</em> and pass <em>nil</em>.</p>

<p>In <a href="http://rayvinly.com/articles/2012/05/02/arc-conversions-explained-part-3-of-3/" target="_blank">Part 3</a>, I will explain what you need to do when you use Objective-C and Core Foundation interchangeably.</p><div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/rayvinly?i=http://rayvinly.com/articles/2012/04/25/arc-conversions-explained-part-2-of-3/" type="text/javascript" charset="utf-8"></script></div>]]></content:encoded>
			<wfw:commentRss>http://rayvinly.com/articles/2012/04/25/arc-conversions-explained-part-2-of-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ARC Conversions Explained &#8211; Part 1 of 3</title>
		<link>http://rayvinly.com/articles/2012/04/18/arc-conversions-explained-part-1-of-3/</link>
		<comments>http://rayvinly.com/articles/2012/04/18/arc-conversions-explained-part-1-of-3/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 09:00:31 +0000</pubDate>
		<dc:creator>Raymond Law</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[ARC]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://rayvinly.com/?p=218</guid>
		<description><![CDATA[The iOS SDK from Apple introduces Automatic Reference Counting (ARC). You can now stop thinking about all those retain, release, and autorelease, so that you can focus on the code instead of memory management. ARC is available if you use the new and better LLVM 3.0 compiler. If you create a new project in Xcode [...]]]></description>
			<content:encoded><![CDATA[<p>The iOS <span class="caps">SDK </span>from Apple introduces <a href="http://bit.ly/IVCwka" target="_blank">Automatic Reference Counting (ARC)</a>. You can now stop thinking about all those retain, release, and autorelease, so that you can focus on the code instead of memory management. <span class="caps">ARC </span>is available if you use the new and better <span class="caps">LLVM</span> 3.0 compiler. If you create a new project in Xcode 4.2, these are already used as defaults. For old projects created with previous versions of Xcode, you can choose <strong>Edit &gt; Refactor &gt; Convert to Objective-C <span class="caps">ARC</span></strong> to ask Xcode to update all or some of your source files to use <span class="caps">ARC.</span> This means you can use <span class="caps">ARC </span>for application specific files but still use manual memory management for old libraries you developed or third-party libraries.</p>

<p>This sounds great, but there are always caveats as we all know it. The fact that the iOS <span class="caps">SDK </span>consists of both Objective-C and C libraries (e.g. Address Book, Core Foundation, Core Image, Core Graphics, &#8230;etc.) means we really need to have a good understanding of how manual memory management works to use <span class="caps">ARC </span>effectively.</p>

<p>When you use <strong>Edit &gt; Refactor &gt; Convert to Objective-C <span class="caps">ARC</span></strong>, Xcode shows the changes it is about to make in a diff view. Instead of just clicking the Save button and let Xcode to update the sources. Let&#8217;s try to understand the changes it is trying to make, so that we won&#8217;t be surprised when the app fails to build or crash when run.</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UILabel <span style="color: #002200;">*</span>label;
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, strong<span style="color: #002200;">&#41;</span> IBOutlet UILabel <span style="color: #002200;">*</span>label;</pre></div></div>




<p>What is the difference between retain and strong?</p>

<p>A <strong>retain</strong> property says to the compiler that the property should increment the reference count by 1 when it is set to an object. When you no longer needs the object, you need to call release on it before setting it to a new object. This is manual memory management.</p>

<p>A <strong>strong</strong> property means the property is a strong pointer to an object. If pointer A is a strong pointer and both pointers A and B point to the same object, when pointer B points is set to point to something else. Pointer A is still valid because it keeps a reference to the object it points to. However, if pointer A is a weak pointer, when pointer B is set to point to something else, pointer A becomes nil because it is too weak to keep the object alive.</p>

<p>What does this mean with <span class="caps">ARC</span>? A retain property should only be used when you are not using <span class="caps">ARC, </span>since you are expected to call release when you no longer needs the object the property points to. However, <span class="caps">ARC </span>handles calling release for us when it compiles, that means we are not supposed to call retain and in fact we cannot because the compiler would complain. Therefore, we tell <span class="caps">ARC </span>that the property is a strong property so when <span class="caps">ARC </span>detects it is no longer needed, it can release it for us.</p>

<p>If we were to declare the property as a weak property, since weak pointers do not keep the object alive, when it is set to point to an object and if it is the only pointer that points to that object, it will not hold the object, and we would get a crash.</p>

<p>As you can see, while <span class="caps">ARC </span>can help us handle most memory management and free us to develop the application. It does not mean we don&#8217;t need to understand memory management. In future episodes of this <span class="caps">ARC </span>series, I will point out more caveats of using <span class="caps">ARC </span>and what we need to understand deeper in order to use it correctly and effectively.</p>

<h3><span class="caps">TIP </span>#1:</h3>

<p>You can create a strong pointer using:</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>version <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;iPhone 4S&quot;</span>;
__strong <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>strongVersion <span style="color: #002200;">=</span> version;</pre></div></div>




<p>or just:</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>version <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;iPhone 4S&quot;</span>;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>strongVersion <span style="color: #002200;">=</span> version;</pre></div></div>




<p>since variables are strong by default. When you call <em>[version release]</em>, <em>strongVersion</em> is still valid.</p>

<p>You create a weak pointer using:</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>version <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;iPhone 4S&quot;</span>;
__weak <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>weakVersion <span style="color: #002200;">=</span> version;</pre></div></div>




<p>When you call <em>[version release]</em>, <em>weakVersion</em> becomes <em>nil</em>.</p>

<h3><span class="caps">TIP </span>#2:</h3>

<p>You need to create delegate property as a weak property, like so:</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> MyViewController <span style="color: #002200;">:</span> UIViewController
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, weak<span style="color: #002200;">&#41;</span> <span style="color: #a61390;">id</span> &lt;MyDelegate&gt; delegate;
<span style="color: #a61390;">@end</span></pre></div></div>




<p>This is important. If we were to declare the delegate as a strong property, when an object of <em>MyViewController</em> is created, it has a strong pointer to the <em>MyDelegate</em> delegate, and the <em>MyDelegate</em> delegate also has a strong pointer to the <em>MyViewController</em> object. When <em>MyViewController</em> is released, it needs to release <em>MyDelegate</em>. When <em>MyDelegate</em> is released, it needs to release <em>MyViewController</em>. It is a never-ending cycle! Therefore, we need to make <em>MyDelegate</em> a weak pointer to <em>MyViewController</em> so that they can be properly released.</p>

<p>In <a href="http://rayvinly.com/articles/2012/04/25/arc-conversions-explained-part-2-of-3/" target="_blank">Part 2</a>, I will explain <em>retain</em>, <em>release</em>, and <em>autorelease</em> and why they aren&#8217;t needed anymore when you use <span class="caps">ARC.</span></p><div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/rayvinly?i=http://rayvinly.com/articles/2012/04/18/arc-conversions-explained-part-1-of-3/" type="text/javascript" charset="utf-8"></script></div>]]></content:encoded>
			<wfw:commentRss>http://rayvinly.com/articles/2012/04/18/arc-conversions-explained-part-1-of-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New Apple products</title>
		<link>http://rayvinly.com/articles/2007/09/07/new-apple-products/</link>
		<comments>http://rayvinly.com/articles/2007/09/07/new-apple-products/#comments</comments>
		<pubDate>Fri, 07 Sep 2007 11:48:36 +0000</pubDate>
		<dc:creator>Raymond Law</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Random]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Apple announced quite a few new products for the holiday season a couple days ago. The iPod nano with a widescreen for video and the iPod touch seem to garner the most attention. I am not a big on-the-go music fan and I don&#8217;t own an iPod and can really use the iPod touch with [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://images.apple.com/home/2007/images/ipod_hero_touch_20070905.jpg" alt="" class="left" style="float:left" /></p>

<p>Apple announced quite a few new products for the holiday season a couple days ago.  The <a href="http://www.apple.com/ipodnano/">iPod nano</a> with a widescreen for video and the <a href="http://www.apple.com/ipodtouch/">iPod touch</a> seem to garner the most attention.  I am not a big on-the-go music fan and I don&#8217;t own an iPod and can really use the iPod touch with the cool touch screen interface.  It also has Safari built in so I can browse over wi-fi.  It works just like the iPhone and who doesn&#8217;t love the iPhone?</p>

<p>However, after some more thoughts, if I can only use Safari  when I am in a wi-fi hotspot, what&#8217;s the point if I already plan to get myself a macbook?  The only difference would be the touch screen <span class="caps">UI, </span>but is it really better than a macbook&#8217;s <span class="caps">UI, </span>with a keyboard and a mouse?  No.  Touch screen is cool but the iPod touch is just for play.  I ain&#8217;t gonna shell out $299 or $399 for something that I can  do better with a macbook.</p>

<p>What would be really cool is some 3rd party developers write a Skype app that can appear as an icon on the iPhone or iPod touch so I can totally bypass the cellular network when I have city-wide wi-fi access.  Then I can save some cell phone bills.</p>

<p>Oh, a larger capacity with both flash and hard drive would be a nice addition as 16GB is really not enough nowadays.  The iPod nano does have a 160GB option.  I guess you can&#8217;t get &#8216;em all in one&#8230;</p><div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/rayvinly?i=http://rayvinly.com/articles/2007/09/07/new-apple-products/" type="text/javascript" charset="utf-8"></script></div>]]></content:encoded>
			<wfw:commentRss>http://rayvinly.com/articles/2007/09/07/new-apple-products/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone drag and drop</title>
		<link>http://rayvinly.com/articles/2007/07/15/iphone-drag-and-drop/</link>
		<comments>http://rayvinly.com/articles/2007/07/15/iphone-drag-and-drop/#comments</comments>
		<pubDate>Sun, 15 Jul 2007 18:45:04 +0000</pubDate>
		<dc:creator>Raymond Law</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[googlemap]]></category>
		<category><![CDATA[map]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I had a chance to play with the iPhone at an Apple store yesterday. I found that if you go to Google Map or any Google Map mashup in Safari, you can&#8217;t drag the map! This is because the iPhone interprets your finger dragging as dragging the web page, not the Google Map on the [...]]]></description>
			<content:encoded><![CDATA[<p>I had a chance to play with the <a href="http://www.apple.com/iphone/">iPhone</a> at an <a href="http://www.apple.com">Apple</a> store yesterday.  I found that if you go to <a href="http://maps.google.com/">Google Map</a> or any Google Map mashup in Safari, you can&#8217;t drag the map!  This is because the iPhone interprets your finger dragging as dragging the web page, not the Google Map on the web page.</p>

<p>The Google Map integrated into the iPhone itself works great though.  Is this a bug or am I just missing something?  Hopefully Apple fixes this soon because this means all websites that have drag and drop like <a href="http://www.tadalist.com/">Ta-da list</a> are not usable (though I have not tried Ta-da list on the iPhone).</p>

<p><strong>Update:</strong> Just headed over to the <a href="http://developer.apple.com/iphone/">iPhone Developer Site</a>.  According to Apple&#8217;s Web Development Guidelines:</p>

<p>&#8220;A few other things to keep in mind about fingers as an input device:<br />
* There are no gestures to perform cut, copy, paste, drag-and-drop, and text selection operations.<br />
* The width of a finger limits the density of links on a page. If the links are too close, your users won&Atilde;&cent;&acirc;‚&not;&acirc;„&cent;t be able to choose a single one.&#8221;</p>

<p>So the answer is no, at least for now.</p><div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/rayvinly?i=http://rayvinly.com/articles/2007/07/15/iphone-drag-and-drop/" type="text/javascript" charset="utf-8"></script></div>]]></content:encoded>
			<wfw:commentRss>http://rayvinly.com/articles/2007/07/15/iphone-drag-and-drop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

