<?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; Apple</title>
	<atom:link href="http://rayvinly.com/articles/category/apple/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>SwitchEasy makes it easy</title>
		<link>http://rayvinly.com/articles/2012/05/04/switcheasy-makes-it-easy/</link>
		<comments>http://rayvinly.com/articles/2012/05/04/switcheasy-makes-it-easy/#comments</comments>
		<pubDate>Fri, 04 May 2012 12:30:20 +0000</pubDate>
		<dc:creator>Raymond Law</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[case]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[switcheasy]]></category>

		<guid isPermaLink="false">http://rayvinly.com/?p=283</guid>
		<description><![CDATA[I blogged about the really bad customer service experiences of Verizon FiOS and Cox Communications. It is time to reverse the tone and say some good words about SwitchEasy who makes iDevices accessories. I owned three Colors iPhone 4S cases, one iPad 2 CoverBuddy back case, and most recently a Canvas folio case for my [...]]]></description>
			<content:encoded><![CDATA[<p>I blogged about the really bad customer service experiences of <a href="http://rayvinly.com/articles/2009/12/29/verizon-fios-has-the-absolutely-worst-customer-service/" target="_blank">Verizon FiOS</a> and <a href="http://rayvinly.com/articles/2012/04/23/10-dollars-offer-to-switch-away-from-cox/" target="_blank">Cox Communications</a>. It is time to reverse the tone and say some good words about <a href="http://www.switcheasy.com/" target="_blank">SwitchEasy</a> who makes iDevices accessories. I owned three Colors iPhone 4S cases, one iPad 2 CoverBuddy back case, and most recently a Canvas folio case for my new iPad. Obviously, they make high quality stuff, so I keep buying. I want to write about my latest experience on the Canvas folio case.</p>

<p>I considered both the <a href="http://www.switcheasy.com/product/CANVAS_ThenewiPad" target="_blank">SwitchEasy Canvas</a> and <a href="http://www.marware.com/c-e-o-hybrid-case-for-the-new-ipad" target="_blank">Marware <span class="caps">C.E.O.</span> Hybrid Case</a> and had a tough time deciding which one to get. I ended up getting the Canvas because my wife liked the pink CoverBuddy for here iPad 2 a lot. They also have CoverBuddy for the new iPad but I wanted better protection when I meet my customers and show them the iPad and iPhone apps we build for my business.</p>

<h2>Product</h2>

<p>I bought the Canvas in charcoal. It shipped the next day and arrived within 3 days. They sent it from their California warehouse to Virginia. The case itself is really, really well made. It has the kind of professional and outgoing look, but does not look too serious and dull. The texture is very nice to touch and feel. I can&#8217;t stress it enough. It is really nice to touch. Sometimes, I just put it on the table and look at it and admire it. However, it does have a strong smell because it is new, which has subdued over a week now.</p>

<p>I use it as a stand in landscape mode all the time. I especially like the outside of the front cover touches the table surface so that the inside of the front cover stays clean. When you are at a coffee shop or food court and try to use your iPad, you know why I like it that way.</p>

<p>It comes with two headphone jack protectors and dock connector protectors, a screen protector, a cloth and squeegee. They are standard stuff with most SwitchEasy products, but are nice for me since I am annoyed when I see dust accumulating inside jacks. I also dislike oily screens when other people use my iPad after eating chips and what not.</p>

<h2>Customer Service</h2>

<p>When I applied the screen protector, I accidentally let the adhesive side (i.e. the side that touches the iPad) touch the cloth. As a result, I had a very dusty screen protector with a lot of black particles. When it happened, I knew it right away I fucked it up pretty badly. However, the iPad now sports a very good display that is kind of hard to scratch, so I figured I will just use the case without the screen protector. After all, that is how my wife uses her iPad 2 and there isn&#8217;t a single scratch after more than a year of heavy use. I also figured it wouldn&#8217;t hurt to tell SwitchEasy about what happened and if they would send me a replacement screen protector, especially they are just plastic.</p>

<p>I actually have the full text of the support request from SwitchEasy. I will just let it describes my experience.</p>

<blockquote>
<h6>Raymond Law, Apr 12 05:30 pm (PDT):</h6>
I received the new Canvas today and am very happy with the case. However, when I applied the Screen Guard to the iPad, the adhesive side of the Screen Guard touched the cloth that came with the case accidentally, and thus attracted a very large amount of dust particles. I tried very hard to clean it but still could not get them off.

<p>I realize this is my own fault. However, it ruins the whole experience of the case for me. I&#8217;ve bought cases for all our iPhones and iPads in my family from SwitchEasy. Would you be so kind to send me another Screen Guard so I can apply it to my iPad more carefully this time?</p>

<p>Thank you very much.</p>


<h6>Jordan, Apr 13 01:22 pm (PDT):</h6>
Hey Raymond,

<p>Typically we do not send replacement Screen Protectors out, but We will go ahead and make an exception for you! We will have a set of New Pure Protect Screen Protectors for the New iPad/ iPad 2 out to you today. Please just verify your Transaction ID from PayPal and also your current Shipping address. As soon as we receive that information we will go ahead and have the package out in the mail for you!</p>

<p>I would I also recommend watching some YouTube Videos to possibly make it a bit easier on how to apply your Screen Protectors with no Bubbles. I do know it can be extremely tricky!</p>


<p>Thanks again,</p>

<p>Jordan <br />
SwitchEasy US Customer Service</p>


<h6>Raymond Law, Apr 13 03:04 pm (PDT):</h6>
Hi Jordan,

<p>Thank you a lot. You made this a happy day for me. My PayPal transaction ID is <span class="caps">XXXXXXXXXXXXXXXXX </span>and my shipping address is:</p>

<p>Raymond Law<br />
<span class="caps">XXXXXXXXXXXXX</span><br />
<span class="caps">XXXXXXXXXXXXX</span></p>

<p>I actually clean the iPad with the cloth after a hot shower to let the dusts settle first. But it was an accident that the adhesive side of the screen protector dropped on the cloth. When it happened, I was like: &#8220;Oh no&#8230;&#8221; And I could never get the dusts off. Do you have some recommended links to some videos of applying them?</p>

<p>Thank you very much.</p>


<h6>Jordan, Apr 13 03:16 pm (PDT):</h6>
Hey Raymond,

<p>Accidents happen, we understand. The Screen Protectors will be out in the mail for you today. The tracking information has been sent to your email address her so you may log onto www.USPS.com to view all locations of this package.</p>

<p>As for Help Videos, go ahead and YouTube how to apply SwitchEasy Screen Protectors for iPad OR how to install screen protectors for iPad. Some are more helpful to others so I can not tell you an exact video to watch. I would say watching a few would be more helpful then just one because you can pick up different tips that may be helpful.</p>

<p>Have a Great Weekend!!!</p>

<p>Best,</p>

Jordan <br />
SwitchEasy US Customer Service<br />
</blockquote>

<p>What a nice gesture! Jordan shows understanding of a customer&#8217;s experience and did something about it. I later found out the screen protector is priced at $14.99. Am I going to consider SwitchEasy cases for my iPhone 5, 6, 7, &#8230;, and newer iPad, newerer iPad, newererer iPad, &#8230;etc? Absolutely. It is really a small price to pay to keep a customer happy and return, and spread good words about the experience. Hence this blog post.</p>

<p>For some reasons, bigger companies like <a href="http://rayvinly.com/articles/2012/04/23/10-dollars-offer-to-switch-away-from-cox/" target="_blank">Cox never learns after so many years</a>. <a href="http://rayvinly.com/articles/2009/12/29/verizon-fios-has-the-absolutely-worst-customer-service/" target="_blank">Verizon Wireless customer service</a> was really good compared to that of FiOS, at least a few years back. I hope they also improved now. I will found out when I talk to them when I help my parents pick the next Internet provider.</p>

<p><strong>Little Disclosure:</strong> SwitchEasy is a Hong Kong-based company and I am originally from Hong Kong too, but the above story was based on a truly happy <img src='http://rayvinly.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  customer experience without cultural bias. I am proud that a Hong Kong company can be this good. I hope they are equally good when treating customers in all continents.</p><div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/rayvinly?i=http://rayvinly.com/articles/2012/05/04/switcheasy-makes-it-easy/" type="text/javascript" charset="utf-8"></script></div>]]></content:encoded>
			<wfw:commentRss>http://rayvinly.com/articles/2012/05/04/switcheasy-makes-it-easy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>I hate TSA and laugh at their stupidity</title>
		<link>http://rayvinly.com/articles/2008/03/11/i-hate-tsa-and-laugh-at-their-stupidity/</link>
		<comments>http://rayvinly.com/articles/2008/03/11/i-hate-tsa-and-laugh-at-their-stupidity/#comments</comments>
		<pubDate>Tue, 11 Mar 2008 15:58:57 +0000</pubDate>
		<dc:creator>Raymond Law</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[airport]]></category>
		<category><![CDATA[macbook]]></category>
		<category><![CDATA[macbookair]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[tsa]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[TSA stupidity on Macbook Air Seriously, TSA is just wasting the government&#8217;s (hence our tax) money and does not provide much in return. They are known to harrass regular traverlers. I was once a victim while traveling on work. I wrote an essay about it but am not sure if I should post it&#8230; FUCK [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://truemors.com/?p=26743"><span class="caps">TSA </span>stupidity on Macbook Air</a></p>

<p>Seriously, <span class="caps">TSA </span>is just wasting the government&#8217;s (hence our tax) money and does not provide much in return.  They are known to harrass regular traverlers.  I was once a victim while traveling on work.  I wrote an essay about it but am not sure if I should post it&#8230;</p>

<p><span class="caps">FUCK TSA</span>!</p><div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/rayvinly?i=http://rayvinly.com/articles/2008/03/11/i-hate-tsa-and-laugh-at-their-stupidity/" type="text/javascript" charset="utf-8"></script></div>]]></content:encoded>
			<wfw:commentRss>http://rayvinly.com/articles/2008/03/11/i-hate-tsa-and-laugh-at-their-stupidity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Another reason not to get the Macbook Air&#8230;</title>
		<link>http://rayvinly.com/articles/2008/03/10/another-reason-not-to-get-the-macbook-air/</link>
		<comments>http://rayvinly.com/articles/2008/03/10/another-reason-not-to-get-the-macbook-air/#comments</comments>
		<pubDate>Mon, 10 Mar 2008 20:11:33 +0000</pubDate>
		<dc:creator>Raymond Law</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[macbook]]></category>
		<category><![CDATA[macbookair]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Apparently, the Macbook Air is known to disappear into thin air&#8230; LOL]]></description>
			<content:encoded><![CDATA[<p>Apparently, the Macbook Air is known to <a href="http://truemors.com/?p=26705">disappear into thin air</a>&#8230; <span class="caps">LOL</span></p><div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/rayvinly?i=http://rayvinly.com/articles/2008/03/10/another-reason-not-to-get-the-macbook-air/" type="text/javascript" charset="utf-8"></script></div>]]></content:encoded>
			<wfw:commentRss>http://rayvinly.com/articles/2008/03/10/another-reason-not-to-get-the-macbook-air/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Time Capsule</title>
		<link>http://rayvinly.com/articles/2008/01/15/time-capsule/</link>
		<comments>http://rayvinly.com/articles/2008/01/15/time-capsule/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 16:27:59 +0000</pubDate>
		<dc:creator>Raymond Law</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[macbook]]></category>
		<category><![CDATA[macbookair]]></category>
		<category><![CDATA[timecapsule]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Apple announces the Time Capsule today at Macworld 2008. I returned an Airport Extreme 2 months ago because it kept dropping my Macbook after waking from sleep w/o power plugged in. It was a very frustrating experience, so I went back to the DI-524, although it also drops my Macbook whenever I turned on my [...]]]></description>
			<content:encoded><![CDATA[<p>Apple announces the <a href="http://www.apple.com/timecapsule/">Time Capsule</a> today at Macworld 2008.</p>

<p>I returned an Airport Extreme 2 months ago because it kept dropping my Macbook after waking from sleep w/o power plugged in.  It was a very frustrating experience, so I went back to the DI-524, although it also drops my Macbook whenever I turned on my Wii.  But I only have to turn Airport off and on and it works again.  The Airport Extreme worked for 30 seconds, then I turned it off/on, worked for another 30 seconds, turned off/on,&#8230;  The firmware is a piece of junk.</p>

<p>Now if Time Capsule does not have the same problem with Airport Extreme, I will probably get one to replace my crappy <span class="caps">NAT </span>and get a 500GB HD for Time Machine.</p>

<p>Airport Extreme $180<br />
500GB HD ~$100</p>

<p>So Time Capsule is priced much more reasonable than the Macbook Air, but only if it actually works and doesn&#8217;t drop connections.</p><div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/rayvinly?i=http://rayvinly.com/articles/2008/01/15/time-capsule/" type="text/javascript" charset="utf-8"></script></div>]]></content:encoded>
			<wfw:commentRss>http://rayvinly.com/articles/2008/01/15/time-capsule/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Macbook Air</title>
		<link>http://rayvinly.com/articles/2008/01/15/macbook-air/</link>
		<comments>http://rayvinly.com/articles/2008/01/15/macbook-air/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 16:19:33 +0000</pubDate>
		<dc:creator>Raymond Law</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[macbook]]></category>
		<category><![CDATA[macbookair]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Apple announces Macbook Air today at Macworld 2008. At first, the coolness factor had me regretting not waiting to delay my Macbook purchase, but after learning that $1799 only has the 4200rpm 80GB HD and you have to shell out $3098 for a 64GB SSD. I am relieved However, seeing it come out of an [...]]]></description>
			<content:encoded><![CDATA[<p>Apple announces <a href="http://www.apple.com/macbookair/">Macbook Air</a> today at Macworld 2008.</p>

<p>At first, the coolness factor had me regretting not waiting to delay my Macbook purchase, but after learning that $1799 only has the 4200rpm 80GB HD and you have to shell out $3098 for a 64GB <span class="caps">SSD. </span> I am relieved <img src='http://rayvinly.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<p>However, seeing it come out of an envelope was extremely cool.  I do dislike the black keys a bit tho.  I thought making the whole thing aluminum would be more cool.  Biege =&gt; black =&gt; white =&gt; aluminum =&gt; black.  Huh?</p><div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/rayvinly?i=http://rayvinly.com/articles/2008/01/15/macbook-air/" type="text/javascript" charset="utf-8"></script></div>]]></content:encoded>
			<wfw:commentRss>http://rayvinly.com/articles/2008/01/15/macbook-air/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up Ruby on Rails, MySQL, Mongrel, memcached, and RMagick using MacPorts on Mac OS X 10.5 Leopard</title>
		<link>http://rayvinly.com/articles/2007/11/29/setting-up-ruby-on-rails-with-mysql-on-mac-os-x-10-5-leopard/</link>
		<comments>http://rayvinly.com/articles/2007/11/29/setting-up-ruby-on-rails-with-mysql-on-mac-os-x-10-5-leopard/#comments</comments>
		<pubDate>Thu, 29 Nov 2007 01:35:55 +0000</pubDate>
		<dc:creator>Raymond Law</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[macbook]]></category>
		<category><![CDATA[macosx]]></category>
		<category><![CDATA[macports]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I recently got the new Santa Rosa Macbook with Leopard pre-installed and I need to set up the Rails development environment. Basically there are 3 ways to achieve that: 1. Locomotive Locomotive method is simple and self contained. It works very well for Mac OS X 10.4 Tiger. However, the author acknowledges that Locomotive may [...]]]></description>
			<content:encoded><![CDATA[<p>I recently got the new Santa Rosa Macbook with <a href="http://www.apple.com/macosx/">Leopard</a> pre-installed and I need to set up the Rails development environment.</p>

<p>Basically there are 3 ways to achieve that:</p>

<p><strong>1. Locomotive</strong></p>

<p><a href="http://locomotive.raaum.org/">Locomotive</a> method is simple and self contained.  It works very well for Mac OS X 10.4 Tiger.  However, the author acknowledges that Locomotive  <a href="http://sourceforge.net/forum/forum.php?thread_id=1858643&amp;forum_id=491804">may not be Leopard ready</a>.</p>

<p><strong>2. Rails comes with Leopard</strong></p>

<p>That&#8217;s right.  Apple has included Rails by default, as noted by <a href="http://weblog.rubyonrails.org/2007/10/26/today-is-leopard-day"><span class="caps">DHH</span></a>.  This sounds great.  However, that means you will also have to manually install Imagick, RMagick, and all those other stuff that you need for development.  Also, it may be harder to upgrade Ruby or Rails when new versions come out.  You probably need to install from source to upgrade or what not&#8230;</p>

<p><strong>3. MacPorts</strong></p>

<p>You might already have your Rails environment set up using <a href="http://www.macports.org/">MacPorts</a>.  If that&#8217;s the case, why not just use that?  Even if you are like me with a fresh installed Leopard, MacPorts still has its advantages.  For example, you can use MacPorts to upgrade ruby in the future.</p>

<p>I used MacPorts to set up my Rails environment based on these other great articles:</p>


<ul>
<li><a href="http://teabass.com/super-simple-ruby-on-rails-install-with-macports-for-leopard/">Teabass</a></li>
<li><a href="http://www.robbyonrails.com/articles/2007/06/19/installing-ruby-on-rails-and-postgresql-on-os-x-second-edition">Robby on Rails</a></li>
<li><a href="http://michael.biven.org/2006/12/22/starting-mongrel-or-memcached-with-launchd/">Michael Biven</a></li>
<li><a href="http://gorn.ch/archive/2007/01/22/start-memcached-with-launchd.html"> Tobias Ebn&amp;Atilde;ƒ&amp;Acirc;&para;ther</a></li>
</ul>



<p>1. Install the latest Xcode version for Leopard.  <a href="http://developer.apple.com/tools/download/">Download</a> from the Apple website.</p>

<p>2. Install the latest MacPorts version for Leopard.  <a href="http://www.macports.org/">Download</a> from the MacPorts website.</p>

<p>Run this to update MacPorts:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port selfupdate</pre></div></div>




<p>3. Install Ruby, RubyGems, and Rails.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> ruby
<span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> rb-rubygems
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem update <span style="color: #660033;">--system</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rails <span style="color: #660033;">-y</span></pre></div></div>




<p>4. Install MySQL (directly from Andrew Nesbitt, shown here for completeness).</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> mysql5 +server
<span style="color: #c20cb9; font-weight: bold;">sudo</span> launchctl load <span style="color: #660033;">-w</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons<span style="color: #000000; font-weight: bold;">/</span>org.macports.mysql5.plist
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-u</span> mysql mysql_install_db5
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span> ; <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql5<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysqld_safe <span style="color: #000000; font-weight: bold;">&amp;</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>mysql5<span style="color: #000000; font-weight: bold;">/</span>mysqld.sock <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>mysql.sock</pre></div></div>




<p>5. Install mongrel and mongrel_cluster.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> mongrel
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> mongrel_cluster</pre></div></div>




<p>6. Install memcached.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> memcached
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> memcache-client</pre></div></div>




<p>Create a file called /Library/LaunchDaemons/com.danga.memcached.plist, and insert the following:</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plist</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Label<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.danga.memcached<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>OnDemand<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;false</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ProgramArguments<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/opt/local/bin/memcached<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>-d<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>-m<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>64<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>-u<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>www<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>-p<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>11211<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>RunAtLoad<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;true</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plist<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>




<p>In order to launch memcached on boot, enter this in the terminal:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> launchctl load <span style="color: #660033;">-w</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons<span style="color: #000000; font-weight: bold;">/</span>com.danga.memcached.plist</pre></div></div>




<p>7. Install ImageMagick and RMagick</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> ImageMagick
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rmagick</pre></div></div>




<p><strong><span class="caps">NEW</span>!</strong> There are now <a href="http://rmagick.rubyforge.org/install-osx.html">instructions</a> on how to install ImageMagick and RMagick.</p>

<p>8. <em>Optional</em> &#8211; I found out if you have the loaded_plugins gem installed, you may see the following error when running script/console:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>activesupport-1.4.2<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>active_support<span style="color: #000000; font-weight: bold;">/</span>dependencies.rb:<span style="color: #000000;">477</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>const_missing<span style="color: #ff0000;">':NameError: uninitialized constant Gem::Version::NUM_RE</span></pre></div></div>




<p>The reason is MacPorts create two directories to store the RubyGems stuff in /opt/local/lib/ruby/site_ruby and /opt/local/lib/ruby/vendor_ruby.  Ruby&#8217;s $LOAD_PATH looks in site_ruby first but the version.rb in site_ruby does not define Gem::Version::NUM_RE whereas the version.rb in vendor_ruby does.  I&#8217;ve outlined the issue <a href="http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/484e09d92b2d9db4#a9adf1301cb66fc1">here</a>. So I simply swap them:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>site_ruby <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>vendor_ruby_tmp
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>vendor_ruby <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>site_ruby
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>vendor_ruby_tmp <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>vendor_ruby</pre></div></div>




<p>This fixes the error and everything runs well for me, but I would like to hear the experts out there about why there are separate vendor_ruby and site_ruby.</p>

<p>That&#8217;s it.  Hope you find this helpful and please report any problems.</p><div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/rayvinly?i=http://rayvinly.com/articles/2007/11/29/setting-up-ruby-on-rails-with-mysql-on-mac-os-x-10-5-leopard/" type="text/javascript" charset="utf-8"></script></div>]]></content:encoded>
			<wfw:commentRss>http://rayvinly.com/articles/2007/11/29/setting-up-ruby-on-rails-with-mysql-on-mac-os-x-10-5-leopard/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>What did you engrave on your iPod?</title>
		<link>http://rayvinly.com/articles/2007/11/26/what-did-you-engrave-on-your-ipod/</link>
		<comments>http://rayvinly.com/articles/2007/11/26/what-did-you-engrave-on-your-ipod/#comments</comments>
		<pubDate>Mon, 26 Nov 2007 16:09:36 +0000</pubDate>
		<dc:creator>Raymond Law</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[ipod]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[http://www.methodshop.net/games/play/rejectedengraving/index.shtml]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.methodshop.net/games/play/rejectedengraving/index.shtml">http://www.methodshop.net/games/play/rejectedengraving/index.shtml</a></p><div id="flaresmith" class="feedflare"><script src="http://feeds.feedburner.com/~s/rayvinly?i=http://rayvinly.com/articles/2007/11/26/what-did-you-engrave-on-your-ipod/" type="text/javascript" charset="utf-8"></script></div>]]></content:encoded>
			<wfw:commentRss>http://rayvinly.com/articles/2007/11/26/what-did-you-engrave-on-your-ipod/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

