<?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>iPhone Programming Tutorials</title>
	<atom:link href="http://www.icodeblog.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.icodeblog.com</link>
	<description>Conquering the mobile universe</description>
	<lastBuildDate>Tue, 06 Dec 2011 23:02:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Using XCode 4 Snippets</title>
		<link>http://www.icodeblog.com/2011/12/06/using-xcode-4-snippets/</link>
		<comments>http://www.icodeblog.com/2011/12/06/using-xcode-4-snippets/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 23:02:06 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[xcode4]]></category>

		<guid isPermaLink="false">http://www.icodeblog.com/?p=3658</guid>
		<description><![CDATA[Recently, I came across <a href="http://nearthespeedoflight.com/article/xcode_4_code_snippets">this post</a> and fell in love with the idea of using XCode 4 snippets.  Up until I read the post, I had heard they existed, but never really tried them.  After reading the post, I began using his snippets as well as started creating my own.  Now, I would say that my work-flow is faster than ever.  
Here is a quick demonstration of the power of snippets
Type:

ttt

It generates:

#pragma mark - UITableView  ...]]></description>
			<content:encoded><![CDATA[<p>Recently, I came across <a href="http://nearthespeedoflight.com/article/xcode_4_code_snippets">this post</a> and fell in love with the idea of using XCode 4 snippets.  Up until I read the post, I had heard they existed, but never really tried them.  After reading the post, I began using his snippets as well as started creating my own.  Now, I would say that my work-flow is faster than ever.  </p>
<p>Here is a quick demonstration of the power of snippets</p>
<p><b>Type:</b></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ttt</pre></div></div>

<p><b>It generates:</b></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#pragma mark - UITableView Datasource</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>numberOfSectionsInTableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #2400d9;">1</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView numberOfRowsInSection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>section <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #2400d9;">10</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UITableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>cellIdentifier <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Cell&quot;</span>;
&nbsp;
    UITableViewCell <span style="color: #002200;">*</span>cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>tableView dequeueReusableCellWithIdentifier<span style="color: #002200;">:</span>cellIdentifier<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>cell <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITableViewCell alloc<span style="color: #002200;">&#93;</span> initWithStyle<span style="color: #002200;">:</span>UITableViewCellStyleDefault reuseIdentifier<span style="color: #002200;">:</span>cellIdentifier<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    cell.textLabel.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Cell %d&quot;</span>, indexPath.row<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">return</span> cell;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark - UITableView Delegate methods</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView didSelectRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>As you can see, with 3 keystrokes, I now have a fully working table view implementation with sample data.</p>
<p>This article will be another introduction to XCode 4 snippets but focusing on how to set them up as well as share them with your team.</p>
<h4>Adding A Snippet Inside Of XCode</h4>
<p>In my opinion, this is not very obvious.  The snippet library is fairly well hidden.  To bring it up, first ensure that the right side bar is visible in XCode by selecting the right most option of the &#8220;view&#8221; pane in the top right corner of XCode.</p>
<p><a href="http://www.icodeblog.com/wp-content/uploads/2011/12/Screen-Shot-2011-12-06-at-3.16.01-PM.png"><img src="http://www.icodeblog.com/wp-content/uploads/2011/12/Screen-Shot-2011-12-06-at-3.16.01-PM.png" alt="" title="Screen Shot 2011-12-06 at 3.16.01 PM" width="95" height="41" class="alignnone size-full wp-image-3661" /></a></p>
<div style="clear:both">&nbsp;</div>
<p>Now that the right bar is available, click on the &#8220;{}&#8221; option of the bottom most pane.  This will bring up the snippet library.  </p>
<p><a href="http://www.icodeblog.com/wp-content/uploads/2011/12/Screen-Shot-2011-12-06-at-3.17.10-PM.png"><img src="http://www.icodeblog.com/wp-content/uploads/2011/12/Screen-Shot-2011-12-06-at-3.17.10-PM.png" alt="" title="Screen Shot 2011-12-06 at 3.17.10 PM" width="260" height="273" class="alignnone size-full wp-image-3662" /></a></p>
<div style="clear:both">&nbsp;</div>
<p>Feel free to browse the snippets that XCode ships with, however most of them are not very useful.  So, now this is where I feel Apple engineers were a little <em>too</em> clever.  It took me a little while to figure out how to actually add a new snippet.  You would expect some sort of + button or something.  The way you add a new snippet in this case is to write out a chunk of code and drag it into the Code Snippet Library window.</p>
<p>Once you drag the code into the library, it creates a default snippet called &#8220;My Code Snippet&#8221;.  Which again, is just terribly non-obvious.  Now, double click on &#8220;My Code Snippet&#8221;, and then click the &#8220;edit&#8221; button to modify it.</p>
<p><a href="http://www.icodeblog.com/wp-content/uploads/2011/12/Screen-Shot-2011-12-06-at-3.23.42-PM.png"><img src="http://www.icodeblog.com/wp-content/uploads/2011/12/Screen-Shot-2011-12-06-at-3.23.42-PM.png" alt="" title="Screen Shot 2011-12-06 at 3.23.42 PM" width="447" height="298" class="alignnone size-full wp-image-3663" /></a></p>
<div style="clear:both">&nbsp;</div>
<p>Let&#8217;s talk about each of the important fields:</p>
<ol>
<li>Title &#8211; This is just the common name you will use to refer to the snippet.  It will display during autocompletion</li>
<li>Completion Shortcut &#8211; this is the command you will use to invoke the snippet.  For example, I have ttt to automatically create all of the UITableView delegate and datasource methods with sample data.</li>
<li>Completion Scopes &#8211; This is pretty cool.  You can have the same shortcut to represent differnet snippets based on the scope of the document.  For example, you won&#8217;t want to invoke your @property snippets inside of your Class implementation.  So, they get ignored&#8230;</li>
</ol>
<p><strong>Adding dynamic fields</strong></p>
<p>If you notice, many of Apple&#8217;s auto generated classes or snippets (like UIAlertView), have these &#8220;code bubbles&#8221; hinting at the type of data you should put into them.  They are also nice because they allow you to tab between them enabling you to implement the code quicker.  To add your own simply insert this into your code:</p>
<p><strong>&lt;#Text#></strong></p>
<p>Where &#8220;Text&#8221; is whatever you want the code bubble to say.  </p>
<p>That&#8217;s it, when you are finished click done and you should now be able to use your snippets.</p>
<h4>Sharing Snippets</h4>
<p>While XCode doesn&#8217;t have an export button for snippets, they are in a fairly predictable location.  They are located at:</p>
<p><strong>~/Library/Developer/Xcode/UserData/CodeSnippets/</strong></p>
<p>That being said, you could manually share them between developers (zip them up and email) OR you could version control this folder with something like git.  I really like the latter approach.  Any time a developer adds a new snippet to the library, the others just have to pull, restart XCode, and voilÃ  the snippet is there.</p>
<h4>Conclusion</h4>
<p>The only issue now is remembering to actually use your snippets in practice.  It takes some getting used to, but I&#8217;m sure you will get it.  Below, you can download a zip file containing many of the snippets that I use.  Simply unzip it into the folder that I mentioned above.  </p>
<p><a href='http://www.icodeblog.com/wp-content/uploads/2011/12/XCode-4-snippets.zip'>Download My Snippets</a></p>
<p>Happy iCoding!</p>
<p><a href="http://twitter.com/brandontreb">Follow me on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.icodeblog.com/2011/12/06/using-xcode-4-snippets/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>ELCImageGrabber</title>
		<link>http://www.icodeblog.com/2011/11/29/elcimagegrabber/</link>
		<comments>http://www.icodeblog.com/2011/11/29/elcimagegrabber/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 20:24:17 +0000</pubDate>
		<dc:creator>Chris Schepman</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.icodeblog.com/?p=3524</guid>
		<description><![CDATA[As I was working on the <a href="https://github.com/elc/ELCImagePickerController">ELCImagePickerController</a>, bringing it up to speed for iOS 5, I needed to get some images inside my iOS simulator. I did some googling and came up with the handy method of dragging and dropping images onto the simulator and using Safari to save them to a photo album. This is all well and good for four or five photos, but it starts to really slow down after that. Also, if you ever run  ...]]></description>
			<content:encoded><![CDATA[<p>As I was working on the <a href="https://github.com/elc/ELCImagePickerController">ELCImagePickerController</a>, bringing it up to speed for iOS 5, I needed to get some images inside my iOS simulator. I did some googling and came up with the handy method of dragging and dropping images onto the simulator and using Safari to save them to a photo album. This is all well and good for four or five photos, but it starts to really slow down after that. Also, if you ever run into a situation where you need to reset the simulator youâ€™re stuck with doing it all over again. For the love of all that is automation, and of course any excuse to start new project in iOS 5, I knew it was time for a utility to handle this task for me.</p>
<p>With that, I give you <a href="https://github.com/elc/ELCImageGrabber">ELCImageGrabber</a>.</p>
<p><a href="http://www.icodeblog.com/2011/11/29/elcimagegrabber/ios-simulator-screen-shot-oct-17-2011-12-03-16-pm-2/" rel="attachment wp-att-3560"><img src="http://www.icodeblog.com/wp-content/uploads/2011/10/iOS-Simulator-Screen-shot-Oct-17-2011-12.03.16-PM1.png" alt="" width="320" height="480" class="alignnone size-full wp-image-3560" style="float: none" /></a></p>
<p>This was a quick project, so itâ€™s not the prettiest interface, but it sure gets the job done. Tell it how many photos you want and watch as the previews go by and get stored in your photo library. The 64 images at a time limit is imposed by the Google image API for a single request, but there are plenty of ways around it. Also, Iâ€™ve hardcoded the search term in the source code, but perhaps you want rainbows and unicorns instead? I hope people find this useful and change it up to fit their needs as well. Iâ€™d love to see pull requests for any useful features that you lovely readers might add!</p>
<p>Get the code <a href="https://github.com/elc/ELCImagePickerController">here</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icodeblog.com/2011/11/29/elcimagegrabber/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Making UITableViews look not so plain</title>
		<link>http://www.icodeblog.com/2011/11/19/making-uitableviews-look-not-so-plain/</link>
		<comments>http://www.icodeblog.com/2011/11/19/making-uitableviews-look-not-so-plain/#comments</comments>
		<pubDate>Sat, 19 Nov 2011 00:57:33 +0000</pubDate>
		<dc:creator>James Van Metre</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[beginner]]></category>

		<guid isPermaLink="false">http://www.icodeblog.com/?p=3622</guid>
		<description><![CDATA[As most of you probably know, UITableView&#8217;s are incredibly useful and versatile views to be using in your applications.
If you have ever tried to customize a UITableView though, you know that as soon as you start adding lots of UIViews, UILabels, and UImageViews to a cells ContentView, that these tableviews start to scroll slower and slower, and become choppier and choppier.
What we are going to explore today is how to remedy that situation.
To download the entire XCode project, you can  ...]]></description>
			<content:encoded><![CDATA[<p>As most of you probably know, UITableView&#8217;s are incredibly useful and versatile views to be using in your applications.<br />
If you have ever tried to customize a UITableView though, you know that as soon as you start adding lots of UIViews, UILabels, and UImageViews to a cells ContentView, that these tableviews start to scroll slower and slower, and become choppier and choppier.</p>
<p>What we are going to explore today is how to remedy that situation.<br />
To download the entire XCode project, you can find it at:  <a href="http://github.com/elc/ICB_PrettyTableView">http://github.com/elc/ICB_PrettyTableView</a></p>
<p>We are going to build a simple contact viewer, that will display the phones contacts. For each contact, if they have a first name, last name, email and phone number, they will be displayed within one cell, with different colors. The reason this is useful is because it provides the basics for customizing UITableViewCells that can really start to make your application look nice, and still scroll well.<br />
If you don&#8217;t want to have simulated data inside the simulator, check out this post for copying data from your device to the simulator: <a href="http://www.icodeblog.com/2011/11/09/how-to-import-contacts-into-the-iphone-simulator/">How to import contacts into the iphone simulator</a></p>
<p>In this example, we have a standard UITableViewController. We are going to have a couple class variables defined in the header</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span>
<span style="color: #6e371a;">#import &lt;AddressBook/AddressBook.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> ICBTableViewController <span style="color: #002200;">:</span> UITableViewController
<span style="color: #002200;">&#123;</span>
    ABAddressBookRef _addressBook;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>contacts;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p> ABAddressBookRef _addressBook is defined in our header, so that we don&#8217;t have to release it until we dealloc. And the contacts is so that we can hold on to the data for our tableView.<br />
In the main table view controller file we are going to override the &#8211; (void)viewDidLoad to provide some initial configuration of the tableView, as well as loading or generating our data. (We will generate fake data for devices or the simulator that don&#8217;t have address book data)</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>viewDidLoad
<span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>super viewDidLoad<span style="color: #002200;">&#93;</span>;
    self.tableView.backgroundColor <span style="color: #002200;">=</span> UIColor.blackColor;
    self.tableView.separatorStyle <span style="color: #002200;">=</span> UITableViewCellSeparatorStyleNone;
&nbsp;
    ABAddressBookRef addressBook <span style="color: #002200;">=</span> ABAddressBookCreate<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>tempArray <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>ABAddressBookCopyArrayOfAllPeople<span style="color: #002200;">&#40;</span>addressBook<span style="color: #002200;">&#41;</span>;
    tempArray <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>tempArray sortedArrayUsingComparator<span style="color: #002200;">:^</span>NSComparisonResult<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> obj1, <span style="color: #a61390;">id</span> obj2<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>name1 <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>ABRecordCopyCompositeName<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>ABRecordRef<span style="color: #002200;">&#41;</span>obj1<span style="color: #002200;">&#41;</span>;
        <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>name2 <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>ABRecordCopyCompositeName<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>ABRecordRef<span style="color: #002200;">&#41;</span>obj2<span style="color: #002200;">&#41;</span>;
        <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>name1 compare<span style="color: #002200;">:</span>name2<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>tempArray count<span style="color: #002200;">&#93;</span> &gt; <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        self.contacts <span style="color: #002200;">=</span> tempArray;
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #400080;">NSMutableArray</span> <span style="color: #002200;">*</span>tempMutableArray <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> arrayWithCapacity<span style="color: #002200;">:</span><span style="color: #2400d9;">100</span><span style="color: #002200;">&#93;</span>;
        <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; <span style="color: #2400d9;">100</span>; <span style="color: #002200;">++</span>i<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            <span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span>dict <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableDictionary</span> dictionary<span style="color: #002200;">&#93;</span>;
            <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>i <span style="color: #002200;">%</span> <span style="color: #2400d9;">9</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">!=</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
                <span style="color: #002200;">&#91;</span>dict setObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;FirstName%d&quot;</span>, i<span style="color: #002200;">&#93;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;firstName&quot;</span><span style="color: #002200;">&#93;</span>;
            <span style="color: #002200;">&#125;</span>
            <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>i <span style="color: #002200;">%</span> <span style="color: #2400d9;">3</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
                <span style="color: #002200;">&#91;</span>dict setObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;LastName%d&quot;</span>, i<span style="color: #002200;">&#93;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;lastName&quot;</span><span style="color: #002200;">&#93;</span>;
            <span style="color: #002200;">&#125;</span>
            <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>i <span style="color: #002200;">%</span> <span style="color: #2400d9;">3</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span> <span style="color: #002200;">&amp;&amp;</span> <span style="color: #002200;">&#40;</span>i <span style="color: #002200;">%</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
                <span style="color: #002200;">&#91;</span>dict setObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;emailTest%d@test%d.com&quot;</span>, i, i<span style="color: #002200;">&#93;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;email&quot;</span><span style="color: #002200;">&#93;</span>;
            <span style="color: #002200;">&#125;</span>
            <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>i <span style="color: #002200;">%</span> <span style="color: #2400d9;">7</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
                <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">string</span> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%d&quot;</span>, i<span style="color: #002200;">&#93;</span>;
                <span style="color: #a61390;">while</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span><span style="color: #a61390;">string</span> length<span style="color: #002200;">&#93;</span> &lt; <span style="color: #2400d9;">10</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
                    <span style="color: #a61390;">string</span> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #a61390;">string</span> stringByAppendingFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@&quot;</span>, <span style="color: #a61390;">string</span><span style="color: #002200;">&#93;</span>;
                <span style="color: #002200;">&#125;</span>
                <span style="color: #002200;">&#91;</span>dict setObject<span style="color: #002200;">:</span><span style="color: #a61390;">string</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;phone&quot;</span><span style="color: #002200;">&#93;</span>;
            <span style="color: #002200;">&#125;</span>
            <span style="color: #002200;">&#91;</span>tempMutableArray addObject<span style="color: #002200;">:</span>dict<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span>
        self.contacts <span style="color: #002200;">=</span> tempMutableArray;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>As you can see here we have a couple of self.tableView methods we have called to setup the background color, and also the cell separator style.<br />
If you are running this application on a device, or simulator that has contacts, this method will also make a copy of the address book as the data to display. If there is no data in the address book, we create some fake test data just for displaying.<br />
Also don&#8217;t forget to include our &#8211; (void)dealloc method for releasing our _addressBook variable.</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>
    CFRelease<span style="color: #002200;">&#40;</span>_addressBook<span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#91;</span>_contacts release<span style="color: #002200;">&#93;</span>;
    _contacts <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>We have to supply the tableView with our number of rows</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>NSInteger<span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView numberOfRowsInSection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>section
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>self.contacts count<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>The next portion we have to override is the &#8211; (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath so that we can supply the tableView with our cells.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Customize the appearance of table view cells.</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UITableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath
<span style="color: #002200;">&#123;</span>   
&nbsp;
    <span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>CellIdentifier <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ICBTableViewCellIdentifier&quot;</span>;
&nbsp;
    ICBTableViewCell <span style="color: #002200;">*</span>cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>ICBTableViewCell<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>tableView dequeueReusableCellWithIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>cell <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>ICBTableViewCell alloc<span style="color: #002200;">&#93;</span> initWithStyle<span style="color: #002200;">:</span>UITableViewCellStyleDefault reuseIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
        cell.textLabel.textColor <span style="color: #002200;">=</span> UIColor.whiteColor;
    <span style="color: #002200;">&#125;</span>
    cell.tag <span style="color: #002200;">=</span> indexPath.row;
&nbsp;
    <span style="color: #400080;">NSObject</span> <span style="color: #002200;">*</span>object <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.contacts objectAtIndex<span style="color: #002200;">:</span>indexPath.row<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>object isKindOfClass<span style="color: #002200;">:</span><span style="color: #400080;">NSDictionary</span>.class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>cell setDictionary<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>object<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>cell setRecord<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ABRecordRef<span style="color: #002200;">&#41;</span>object<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #a61390;">return</span> cell;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>We are checking each object coming out of our array so that we can determine if we need to call the setDictionary, or setRecord method calls.</p>
<p>Now the meat of this tutorial, extending a UITableViewCell.</p>
<p>In our header we are going to define a bunch of strings that we want to display</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span>
<span style="color: #6e371a;">#import &lt;AddressBook/AddressBook.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> ICBTableViewCell <span style="color: #002200;">:</span> UITableViewCell
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>firstName;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>lastName;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>email;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>phone;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>address;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setRecord<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ABRecordRef<span style="color: #002200;">&#41;</span>record;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setDictionary<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>dict;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>And then our two set methods:</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>setRecord<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ABRecordRef<span style="color: #002200;">&#41;</span>record
<span style="color: #002200;">&#123;</span>
    self.firstName <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>ABRecordCopyValue<span style="color: #002200;">&#40;</span>record, kABPersonFirstNameProperty<span style="color: #002200;">&#41;</span> autorelease<span style="color: #002200;">&#93;</span>;
    self.lastName <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>ABRecordCopyValue<span style="color: #002200;">&#40;</span>record, kABPersonLastNameProperty<span style="color: #002200;">&#41;</span> autorelease<span style="color: #002200;">&#93;</span>;
    self.email <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self getFirstEmail<span style="color: #002200;">:</span>record<span style="color: #002200;">&#93;</span>;
    self.phone <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self getFirstPhone<span style="color: #002200;">:</span>record<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>self setNeedsDisplay<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setDictionary<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>dict
<span style="color: #002200;">&#123;</span>
    self.firstName <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>dict objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;firstName&quot;</span><span style="color: #002200;">&#93;</span>;
    self.lastName <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>dict objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;lastName&quot;</span><span style="color: #002200;">&#93;</span>;
    self.email <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>dict objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;email&quot;</span><span style="color: #002200;">&#93;</span>;
    self.phone <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>dict objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;phone&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>self setNeedsDisplay<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Some tutorials will have you put this next part into a separate UIView subclass, and add that class as the contentView of this UITableViewCell, but I prefer to override the drawRect of the UITableViewCell, and do all my drawing there.</p>
<p>The first thing I am doing is getting the current graphics context so that we can draw to the screen, clipping to the rect that is passed in drawRect:(CGRect)rect, and then depending on whether this cell is even, I am filling the entire rect with an almost black color, or slightly lighter.</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>drawRect<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span>rect
<span style="color: #002200;">&#123;</span>
    CGContextRef ctx <span style="color: #002200;">=</span> UIGraphicsGetCurrentContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
    CGContextClipToRect<span style="color: #002200;">&#40;</span>ctx, rect<span style="color: #002200;">&#41;</span>;
    <span style="color: #11740a; font-style: italic;">//If even</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>self.tag <span style="color: #002200;">%</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        CGContextSetFillColorWithColor<span style="color: #002200;">&#40;</span>ctx, <span style="color: #002200;">&#91;</span>UIColor colorWithWhite<span style="color: #002200;">:</span>0.1f alpha<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span>.f<span style="color: #002200;">&#93;</span>.CGColor<span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
        CGContextSetFillColorWithColor<span style="color: #002200;">&#40;</span>ctx, <span style="color: #002200;">&#91;</span>UIColor colorWithWhite<span style="color: #002200;">:</span>0.15f alpha<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span>.f<span style="color: #002200;">&#93;</span>.CGColor<span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    CGContextFillRect<span style="color: #002200;">&#40;</span>ctx, rect<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>The next thing I am going to figure out is whether I want this text to be centered in the cell, and I am determining this based off whether there is an email field or not.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">    <span style="color: #11740a; font-style: italic;">//Vertically center our text, if no email</span>
    <span style="color: #a61390;">BOOL</span> isCentered <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>self.email <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>And now for the meat of the drawRect method. We calculate the size of firstName, draw it offset from the left by 5, and then draw lastName right after it. We also change the color we are drawing between those two.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">    CGRect tempRect;
    CGFloat midY <span style="color: #002200;">=</span> CGRectGetMidY<span style="color: #002200;">&#40;</span>rect<span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIColor whiteColor<span style="color: #002200;">&#93;</span> set<span style="color: #002200;">&#93;</span>;
    UIFont <span style="color: #002200;">*</span>defaultFont <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIFont systemFontOfSize<span style="color: #002200;">:</span><span style="color: #2400d9;">16</span><span style="color: #002200;">&#93;</span>;
    CGSize size <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.firstName sizeWithFont<span style="color: #002200;">:</span>defaultFont<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>isCentered <span style="color: #002200;">==</span> <span style="color: #a61390;">NO</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        tempRect <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">5</span>, <span style="color: #2400d9;">0</span>, size.width, size.height<span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
        tempRect <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">5</span>, midY <span style="color: #002200;">-</span> size.height<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span>, size.width, size.height<span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#91;</span>self.firstName drawInRect<span style="color: #002200;">:</span>tempRect withFont<span style="color: #002200;">:</span>defaultFont<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIColor lightGrayColor<span style="color: #002200;">&#93;</span> set<span style="color: #002200;">&#93;</span>;
    size <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.lastName sizeWithFont<span style="color: #002200;">:</span>defaultFont<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>isCentered <span style="color: #002200;">==</span> <span style="color: #a61390;">NO</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        tempRect <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span>CGRectGetMaxX<span style="color: #002200;">&#40;</span>tempRect<span style="color: #002200;">&#41;</span><span style="color: #002200;">+</span><span style="color: #2400d9;">5</span>, <span style="color: #2400d9;">0</span>, size.width, size.height<span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
        tempRect <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span>CGRectGetMaxX<span style="color: #002200;">&#40;</span>tempRect<span style="color: #002200;">&#41;</span><span style="color: #002200;">+</span><span style="color: #2400d9;">5</span>, midY <span style="color: #002200;">-</span> size.height<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span>, size.width, size.height<span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#91;</span>self.lastName drawInRect<span style="color: #002200;">:</span>tempRect withFont<span style="color: #002200;">:</span>defaultFont<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Next we find out if phone actually exists, and if so set the color to red, and draw it to the right of lastName. We also have to make sure we aren&#8217;t drawing this outside our boundaries, so we check to see where the end is, and if it is outside, we crop it to 5 pixels from the end.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self.phone <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIColor redColor<span style="color: #002200;">&#93;</span> set<span style="color: #002200;">&#93;</span>;
        size <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.phone sizeWithFont<span style="color: #002200;">:</span>defaultFont<span style="color: #002200;">&#93;</span>;
        CGFloat end <span style="color: #002200;">=</span> CGRectGetMaxX<span style="color: #002200;">&#40;</span>tempRect<span style="color: #002200;">&#41;</span> <span style="color: #002200;">+</span> size.width;
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>end &gt; rect.size.width<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            size.width <span style="color: #002200;">=</span> CGRectGetMaxX<span style="color: #002200;">&#40;</span>rect<span style="color: #002200;">&#41;</span> <span style="color: #002200;">-</span> CGRectGetMaxX<span style="color: #002200;">&#40;</span>tempRect<span style="color: #002200;">&#41;</span> <span style="color: #002200;">-</span> <span style="color: #2400d9;">10</span>; <span style="color: #11740a; font-style: italic;">//-10 so that we get 5 from the end of last name, and 5 from the end of rect</span>
        <span style="color: #002200;">&#125;</span>
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>isCentered <span style="color: #002200;">==</span> <span style="color: #a61390;">NO</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            tempRect <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span>CGRectGetMaxX<span style="color: #002200;">&#40;</span>rect<span style="color: #002200;">&#41;</span> <span style="color: #002200;">-</span> size.width <span style="color: #002200;">-</span> <span style="color: #2400d9;">5</span>, <span style="color: #2400d9;">0</span>, size.width, size.height<span style="color: #002200;">&#41;</span>;
        <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
            tempRect <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span>CGRectGetMaxX<span style="color: #002200;">&#40;</span>rect<span style="color: #002200;">&#41;</span> <span style="color: #002200;">-</span> size.width <span style="color: #002200;">-</span> <span style="color: #2400d9;">5</span>, midY <span style="color: #002200;">-</span> size.height<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span>, size.width, size.height<span style="color: #002200;">&#41;</span>;
        <span style="color: #002200;">&#125;</span>
        <span style="color: #002200;">&#91;</span>self.phone drawInRect<span style="color: #002200;">:</span>tempRect withFont<span style="color: #002200;">:</span>defaultFont lineBreakMode<span style="color: #002200;">:</span>UILineBreakModeTailTruncation<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span></pre></div></div>

<p>And finally if our email actually exists draw it on the bottom left.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self.email <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIColor blueColor<span style="color: #002200;">&#93;</span> set<span style="color: #002200;">&#93;</span>;
        size <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.email sizeWithFont<span style="color: #002200;">:</span>defaultFont<span style="color: #002200;">&#93;</span>;
        tempRect <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">5</span>, midY, size.width, size.height<span style="color: #002200;">&#41;</span>;
        <span style="color: #002200;">&#91;</span>self.email drawInRect<span style="color: #002200;">:</span>tempRect withFont<span style="color: #002200;">:</span>defaultFont<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span></pre></div></div>

<p>I hope this helps you in configuring UITableViewCells for your own project, and hopefully will let you start to think about the possibilities.</p>
<p>To download the entire XCode project, you can find it at:  <a href="http://github.com/elc/ICB_PrettyTableView">http://github.com/elc/ICB_PrettyTableView</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.icodeblog.com/2011/11/19/making-uitableviews-look-not-so-plain/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to import contacts into the iPhone Simulator</title>
		<link>http://www.icodeblog.com/2011/11/09/how-to-import-contacts-into-the-iphone-simulator/</link>
		<comments>http://www.icodeblog.com/2011/11/09/how-to-import-contacts-into-the-iphone-simulator/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 23:41:11 +0000</pubDate>
		<dc:creator>Marc Charbonneau</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Address Book]]></category>
		<category><![CDATA[AddressBook.framework]]></category>
		<category><![CDATA[Contacts]]></category>

		<guid isPermaLink="false">http://www.icodeblog.com/?p=3614</guid>
		<description><![CDATA[If you&#8217;re working with AddressBook.framework chances are you&#8217;ll want to import your own data to test against when you&#8217;re in the simulator. Without being able to sync with iTunes or iCloud you may think you&#8217;re stuck entering in addresses manually; not only is that a huge pain, but there are probably lots of edge cases already in your address book you wouldn&#8217;t necessarily think of.
Fortunately there&#8217;s another option, with a tool called <a href="http://supercrazyawesome.com/">iPhone Backup Extractor</a>. Download it, run it  ...]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re working with AddressBook.framework chances are you&#8217;ll want to import your own data to test against when you&#8217;re in the simulator. Without being able to sync with iTunes or iCloud you may think you&#8217;re stuck entering in addresses manually; not only is that a huge pain, but there are probably lots of edge cases already in your address book you wouldn&#8217;t necessarily think of.</p>
<p>Fortunately there&#8217;s another option, with a tool called <a href="http://supercrazyawesome.com/">iPhone Backup Extractor</a>. Download it, run it and click Read Backups (note that you&#8217;ll need to back up to iTunes, not iCloud). Select your device, and you should see a list of apps included in your backup. Choose the last item on the list, iOS Files, and extract it to your desktop. When it&#8217;s done take a look in the folder it created. You should find two files in the folder <strong>iOS Files/Library/AddressBook</strong>, <strong>AddressBook.sqlitedb</strong> and <strong>AddressBookImages.sqlitedb</strong>.</p>
<p>Next, open the simulator&#8217;s Application Support folder (in the Finder menu, choose <strong>Go</strong> -> <strong>Go to Folder&#8230;</strong>, enter <strong>~/Library/Application Support/iPhone Simulator</strong>, and choose the SDK you&#8217;re working with) and drill down to <strong>Library/AddressBook</strong>. Quit the simulator if it&#8217;s open, delete everything in this directory, then copy the two files noted above from your backup. That&#8217;s it! If everything went well the next time you launch the simulator you should see all your contacts.</p>
<p>Pretty easy, really. If address book data is a major feature of your app, you might even want to have a few trusted beta testers send you their backups so you can test with their contacts. My experience is that there are a lot of unusual or invalid contacts floating around on people&#8217;s phones, and the more opportunity you have to test the better you&#8217;ll do once you release your app.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icodeblog.com/2011/11/09/how-to-import-contacts-into-the-iphone-simulator/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Simple Sqlite Database Interaction Using FMDB</title>
		<link>http://www.icodeblog.com/2011/11/04/simple-sqlite-database-interaction-using-fmdb/</link>
		<comments>http://www.icodeblog.com/2011/11/04/simple-sqlite-database-interaction-using-fmdb/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 19:52:19 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[fmdb]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://www.icodeblog.com/?p=3595</guid>
		<description><![CDATA[Introduction
In the age where Core Data is king, the database that started it all is often overlooked.  I&#8217;m talking of course about sqlite.  As you may or may not know, prior to core data, sqlite was the preferred method of storing relational data on iOS devices.
Although, most developers don&#8217;t interact with sqlite directly, they still use it under the hood as the primary data store for core data.  This is great and all, but there are often  ...]]></description>
			<content:encoded><![CDATA[<h4>Introduction</h4>
<p>In the age where Core Data is king, the database that started it all is often overlooked.  I&#8217;m talking of course about sqlite.  As you may or may not know, prior to core data, sqlite was the preferred method of storing relational data on iOS devices.</p>
<p>Although, most developers don&#8217;t interact with sqlite directly, they still use it under the hood as the primary data store for core data.  This is great and all, but there are often times when raw sqlite is still the preferred storage method.</p>
<p>A few of these might include:</p>
<ul>
<li>Caching</li>
<li>Preferences</li>
<li>Simple objects</li>
<li>Portability</li>
<li>Cross platform applications</li>
</ul>
<p>Recently, I have had to make heave use of raw sqlite as a caching strategy in a new project that I&#8217;m working on.  Being that we are developing a framework for other developers to include in their projects, we can&#8217;t always assume that they have their environment set up to use core data.  When I was but a n00b iOS developer I did all of the crazy sqlite management by hand. See <a href="http://www.icodeblog.com/2008/08/19/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-1/">This post series</a>, but don&#8217;t spend too much time there because it&#8217;s embarrassing.</p>
<p>Gross right? Now, there is a much easier way to manage and interact with your sqlite databases.  This library has been around for quite some time and I wish I had known about it earyly on.</p>
<h4>FMDB</h4>
<p>FMDB stands for Flying Meat Database.  What a great name&#8230; This project aims to be a fully featured wrapper for sqlite.</p>
<p>You can clone their repository on <a href="https://github.com/ccgus/fmdb">their github</a>.</p>
<p>This tutorial will give you a brief introduction to using FMDB to create a database, create a table, insert, fetch, and delete data.</p>
<h4>Project Set Up</h4>
<p>The first step is to download/clone fmdb from the url above.  Once downloaded drag everything inside of the src folder into your project <strong>except</strong> fmdb.m.  That file contains unit tests and a main, which will cause some conflicts in your project.</p>
<p>The next step is to link in the sqlite library.  To do this:</p>
<ol>
<li>Click your project in the left column of XCode</li>
<li>Click the main target in the middle column. In our case it&#8217;s &#8220;FMDBTest&#8221;</li>
<li>Click the &#8220;Build Phases&#8221; tab in the third column</li>
<li>Expand the arrow next to &#8220;Link Binary With Libraries&#8221;</li>
<li>Click the &#8220;+&#8221; button</li>
<li>Search for libsqlite3.0.dylib and double click it</li>
</ol>
<p>When you are all done, it should look like this:</p>
<p><img src="http://www.icodeblog.com/wp-content/uploads/2011/11/Screen-Shot-2011-11-04-at-12.48.10-PM.png" alt="Screenshot" title=""></p>
<div style="clear:both">
<p>Now, that we have the library in place, let&#8217;s write some code.</p>
<h4>Creating A Database</h4>
<p>Obviously <em>where</em> you create your database is up to you, but we are going to do it in the appDelegate.</p>
<p>In addition to working with existing databases, fmdb can <em>easily</em> create any number of databases for you on the fly.  After importing FMDatabase.h in our AppDelegate.m file, we can add the following code to the <code>application:didFinishLaunching</code> method.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>paths <span style="color: #002200;">=</span> NSSearchPathForDirectoriesInDomains<span style="color: #002200;">&#40;</span>NSDocumentDirectory, NSUserDomainMask, <span style="color: #a61390;">YES</span><span style="color: #002200;">&#41;</span>;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>docsPath <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>paths objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>path <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>docsPath stringByAppendingPathComponent<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;database.sqlite&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
FMDatabase <span style="color: #002200;">*</span>database <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>FMDatabase databaseWithPath<span style="color: #002200;">:</span>path<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>First, we resolve the path to the documents directory. Be careful, if you don&#8217;t <em>need</em> your database to be backed up, use the cache directory instead.  When you send a path to the databaseWithPath method of fmdb, it first checks if the database exists, and if not, it creates it.  Similarly, we could copy an existing database to the documents directory and source it the exact same way.</p>
<h4>Opening The Database And Creating Tables</h4>
<p>In order to perform any action on the database, it must first be opened.  Here is the code to open the database and create a users table. Don&#8217;t worry about closing it right now, we will do that when we are all done.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>database open<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>database executeUpdate<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;create table user(name text primary key, age int)&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Here we first call the open method of the database to open it.  Next, we use the executeUpdate method to create the table. Make sure you use this method and <strong>not</strong> executeQuery when creating a table.  This is a common error.  The database should look like this after our update:</p>
<p><img src="http://www.icodeblog.com/wp-content/uploads/2011/11/Screen-Shot-2011-11-04-at-1.05.12-PM.png" width="550" alt="Screenshot" title=""></p>
<div style="clear:both">
<p>After we are all done here we close the database.</p>
<h4>Inserting And Deleting Data</h4>
<p>Inserting data using sqlite is very straight forward.  You can either build your strings and pass them in directly OR use the sqlite format using &#8220;?&#8217;s&#8221; and letting fmdb do the work.  Below is an example of each:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Building the string ourself</span>
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>query <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;insert into user values ('%@', %d)&quot;</span>,
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;brandontreb&quot;</span>, <span style="color: #2400d9;">25</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>database executeUpdate<span style="color: #002200;">:</span>query<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Let fmdb do the work</span>
<span style="color: #002200;">&#91;</span>database executeUpdate<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;insert into user(name, age) values(?,?)&quot;</span>,
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;cruffenach&quot;</span>,<span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumber</span> numberWithInt<span style="color: #002200;">:</span><span style="color: #2400d9;">25</span><span style="color: #002200;">&#93;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Generally, the second route is preferred as fmdb will do some of the sanitizing for your (such as add slashes to single quotes).</p>
<p>Now that we have some data in our database, let&#8217;s delete it.  The following code will delete all users with an age of 25:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>database executeUpdate<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;delete from user where age = 25&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>And that should remove both of the records that we inserted.</p>
<h4>Querying The Database</h4>
<p>Querying the database is a bit more tricky than inserting and deleting.  FMDB has some great utility methods for helping us out in certain circumstances, but for this tutorial, we will assume the don&#8217;t exist and show you how to fetch data out.  If you are following along in a sample application, put this code before your delete code (so that we actually have some data to work with).</p>
<p>Below is an example of fetching all users from the database:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">FMResultSet <span style="color: #002200;">*</span>results <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>database executeQuery<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;select * from user&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #a61390;">while</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>results next<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>name <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>results stringForColumn<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;name&quot;</span><span style="color: #002200;">&#93;</span>;
    NSInteger age  <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>results intForColumn<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;age&quot;</span><span style="color: #002200;">&#93;</span>;        
    NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;User: %@ - %d&quot;</span>,name, age<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#91;</span>database close<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>We first query the database using the <code>executeQuery</code> method.  This returns to us an FMResultsSet.  Next we start a while loop that continues while there are results to be retrieved and fetch out each of our data points.  Finally, we just print out each user. </p>
<p>And finally, our database gets close&#8230;</p>
<h4>Conclusion</h4>
<p>This concludes our sqlite using fmdb tutorial.  As always, if you have any questions, please leave them here or <a href="http://twitter.com/brandontreb">write me on twitter</a>.  </p>
<p>You can download the source for this tutorial <a href="http://www.icodeblog.com/?attachment_id=3599">here</a></p>
<p>Happy iCoding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icodeblog.com/2011/11/04/simple-sqlite-database-interaction-using-fmdb/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>iOS Developers, We Are Hiring!</title>
		<link>http://www.icodeblog.com/2011/10/28/ios-developers-we-are-hiring/</link>
		<comments>http://www.icodeblog.com/2011/10/28/ios-developers-we-are-hiring/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 21:42:40 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.icodeblog.com/?p=3587</guid>
		<description><![CDATA[ELC Technologies is hiring!
At ELC we are proud of more than 100 years of combined application development experience including dynamic languages like Ruby, JRuby, Python, as well as strongly typed languages such as C and Java. Our knowledge of the Cloud lets us build true scalability into products. This experience, coupled with our creativity, has led us to build some of the largest, most used apps out there. We are experts in AGILE development, delivering working software in weeks, not  ...]]></description>
			<content:encoded><![CDATA[<p>ELC Technologies is hiring!</p>
<p>At ELC we are proud of more than 100 years of combined application development experience including dynamic languages like Ruby, JRuby, Python, as well as strongly typed languages such as C and Java. Our knowledge of the Cloud lets us build true scalability into products. This experience, coupled with our creativity, has led us to build some of the largest, most used apps out there. We are experts in AGILE development, delivering working software in weeks, not months or years.</p>
<p>Our customer list includes Fortune 500 companies, major professional sports leagues, and universal media conglomerates. We have successfully completed sophisticated Ruby on Rails solutions, innovative interactive tools, trend setting mobile technologies as well as business critical applications. This has earned us the trust of some of the worldâ€™s largest companies.</p>
<p>We offer all the usual benefits&#8230; and if youâ€™re located in Portland, an office with the world&#8217;s greatest espresso machine, a team of Kung Fu masters, Eight Ball champions, Nerf Gun Assassins, and world authorities on Dungeons and Dragons.</p>
<p>Weâ€™re passionate about many things here at ELC, such as:</p>
<ul>
<li>Creating cross-platform, enterprise level mobile applications with awesome UI/UX.</li>
<li>Building software, mainly in Ruby on Rails but have been known to find the right tool for the right job (Scala, Erlang, and Clojure come to mind).</li>
<li>Having fun, we believe that going to work should carry the same anticipation as that 10 minutes leading up to elementary school recess.</li>
<li>Being Agile, we donâ€™t force-feed one specific process, but pick and choose what is going to work on a per team/per project basis.</li>
<li>Solving real world problems without compromising creativity.</li>
</ul>
<p>Hereâ€™s what we look for in our hires:</p>
<ul>
<li>Strong problem solving skills.</li>
<li>Have at least 1 year experience building iPhone/iPad applications.</li>
<li>Proficiency in Objective-C.</li>
<li>Understand when something should be extracted to an API, and how to leverage existing ones to make your life easier.</li>
<li>Not afraid of trial by fire.</li>
<li>Interest in learning and using new languages in real world situations</li>
<li>Up to date on the latest Internet Memes and Animated GIFs or it didnâ€™t happen.</li>
</ul>
<p>Contact<br />
Please send the following to: Â  <a href="mailto://jobs@elctech.com">jobs@elctech.com</a></p>
<p>1. Â Links to sites you&#8217;ve worked on including a brief description of your contributions.<br />
2. Â Code samples. Anything you feel like best represents your capabilities / strengths.</p>
<p>Company Website URL<br />
<a title="http://elctech.com" href="http://elctech.com"> http://elctech.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.icodeblog.com/2011/10/28/ios-developers-we-are-hiring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update #2: ELCImagePickerController</title>
		<link>http://www.icodeblog.com/2011/10/18/update-elcimagepickercontroller-2/</link>
		<comments>http://www.icodeblog.com/2011/10/18/update-elcimagepickercontroller-2/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 19:10:10 +0000</pubDate>
		<dc:creator>Chris Schepman</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Advanced]]></category>

		<guid isPermaLink="false">http://www.icodeblog.com/?p=3485</guid>
		<description><![CDATA[Welcome back to another update to the <a href="https://github.com/elc/ELCImagePickerController" title="ELCImagePickerController">ELCImagePickerController</a>. If you&#8217;re not familiar with this class I&#8217;d suggest you check out the following posts:
<a href="http://www.icodeblog.com/2010/10/07/cloning-uiimagepickercontroller-using-the-assets-library-framework/" title="Cloning UIImagePickerController using the Assets Library Framework">Cloning UIImagePickerController using the Assets Library Framework</a>
<a href="http://www.icodeblog.com/2011/03/03/update-elcimagepickercontroller/">Update: ELCImagePickerController</a>
A lot has happened in the iOS world since the creation of this code. With the advent of every new version of iOS there are always exciting new features and bug fixes. Sometimes subtle code changes sneak into classes we&#8217;ve  ...]]></description>
			<content:encoded><![CDATA[<p>Welcome back to another update to the <a href="https://github.com/elc/ELCImagePickerController" title="ELCImagePickerController">ELCImagePickerController</a>. If you&#8217;re not familiar with this class I&#8217;d suggest you check out the following posts:</p>
<p><a href="http://www.icodeblog.com/2010/10/07/cloning-uiimagepickercontroller-using-the-assets-library-framework/" title="Cloning UIImagePickerController using the Assets Library Framework">Cloning UIImagePickerController using the Assets Library Framework</a><br />
<a href="http://www.icodeblog.com/2011/03/03/update-elcimagepickercontroller/">Update: ELCImagePickerController</a></p>
<p>A lot has happened in the iOS world since the creation of this code. With the advent of every new version of iOS there are always exciting new features and bug fixes. Sometimes subtle code changes sneak into classes we&#8217;ve been using for a while though. These changes might create bugs that can be hard to find. Whenever I am debugging code on a new release, especially if itâ€™s a beta release, I try to remember to consult the docs sooner than later. When we started to get reports of ELCImagePickerController not working in iOS 5, it was time to do some homework.</p>
<p>The problem seemed to be that the albums were coming up as empty, even when people had plenty of pictures to display. Someone in the community found a quick work around that if you donâ€™t release the library object, then the code starts working again! Leaking memory like this is never the right answer, but it was a great starting spot to figure out the real problem.</p>
<p>The problem seemed to be arising here:</p>
<script src="http://gist.github.com/1294115.js"></script>
<p>Commenting out the release fixed the problem? Very odd. I floundered around the code a bit before remembering to go to the documentation for this new (beta, at the time) version of iOS. Lo and behold!</p>
<p><a href="http://www.icodeblog.com/2011/10/18/update-elcimagepickercontroller-2/screen-shot-2011-10-17-at-10-54-47-am-2/" rel="attachment wp-att-3488"><img class="alignnone size-large wp-image-3488" src="http://www.icodeblog.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-17-at-10.54.47-AM1-600x94.png" alt="" width="600" height="94" /></a></p>
<p>The last sentence is key, &#8220;The lifetimes of objects you get back from a library instance are tied to the life of the library instance.&#8221; If we release our library instance right there we arenâ€™t going to have access to any of the objects we get back from it anymore! This is new behavior in iOS 5. To adapt to it I just moved the library variable out to be an instance variable of the class and didn&#8217;t release it until dealloc is called.</p>
<p>Not such a hard fix once I knew what to look for, just have to remember that the documentation is there for a reason! Thanks to the community for the feedback that made tracking down this bug much easier.</p>
<p><a href="http://www.icodeblog.com/2011/10/18/update-elcimagepickercontroller-2/elc-image-picker-controller-ios5/" rel="attachment wp-att-3580"><img src="http://www.icodeblog.com/wp-content/uploads/2011/10/elc-image-picker-controller-ios5.png" alt="" width="320" height="480" class="alignnone size-full wp-image-3580" style="float: none" /></a></p>
<p>We&#8217;re back in action!</p>
<p>As I was troubleshooting this control I kept running into the problem that my simulator didnâ€™t have any pictures in it. If only there was a utility to populate the photo album for me. Maybe it could grab images of cute little kittens from the internet or something? Hmm. Stay tuned to iCodeBlog for more on this!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icodeblog.com/2011/10/18/update-elcimagepickercontroller-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Back To Basics &#8211; An Introduction To View Controllers</title>
		<link>http://www.icodeblog.com/2011/10/11/back-to-basics-an-introduction-to-view-controllers/</link>
		<comments>http://www.icodeblog.com/2011/10/11/back-to-basics-an-introduction-to-view-controllers/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 18:57:34 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[uiviewcontroller]]></category>

		<guid isPermaLink="false">http://www.icodeblog.com/?p=3462</guid>
		<description><![CDATA[Introduction
In today&#8217;s post, we are going to be discussing view controllers.  Let&#8217;s start by talking about what a view controller is and it&#8217;s role in your iOS projects.
What is a View Controller?
View Controllers are at the core of every application.  They act as sort of the glue between your models and your views.  View controllers are both responsible for fetching/initializing your models as well as loading up your views to display the information within them.
Basic View Controllers
Every  ...]]></description>
			<content:encoded><![CDATA[<h4>Introduction</h4>
<p>In today&#8217;s post, we are going to be discussing <strong>view controllers</strong>.  Let&#8217;s start by talking about what a view controller is and it&#8217;s role in your iOS projects.</p>
<h4>What is a View Controller?</h4>
<p>View Controllers are at the core of every application.  They act as sort of the glue between your models and your views.  View controllers are both responsible for fetching/initializing your models as well as loading up your views to display the information within them.</p>
<h4>Basic View Controllers</h4>
<p>Every view controller that Apple provides extends from the base <strong>UIViewController</strong> subclass.  This gives them a few basic properties that you will find handy. The most important of course is the <strong>view</strong> property.  This is a reference to the view that the controller is managing.</p>
<p>Along with some default properties, you also get some powerful methods that allow each UIViewController subclass to easily interact with all of the common view controllers.</p>
<p>Here are some of the basic view controllers to be discussed in this post:</p>
<ul>
<li>UINavigationController</li>
<li>UITableViewController</li>
<li>UITabBarController</li>
</ul>
<p>I picked these 3 controllers since they are the most common and are automatically created in the main project templates when creating a new XCode project.</p>
<h4>UINavigationController</h4>
<div id="attachment_3464" class="wp-caption alignnone" style="width: 610px"><a href="http://www.icodeblog.com/2011/10/11/back-to-basics-an-introduction-to-view-controllers/navigation_interface/" rel="attachment wp-att-3464"><img src="http://www.icodeblog.com/wp-content/uploads/2011/10/navigation_interface-600x270.jpg" alt="" title="navigation_interface" width="600" class="size-large wp-image-3464" /></a><p class="wp-caption-text">Basic Navigation Interface</p></div>
<p>Generally we don&#8217;t talk about UINavigationControllers outside of the context of a <strong>UITableViewController</strong>, however we need to discuss them prior in order to see what&#8217;s going on under the hood.  </p>
<p>UINavigationController are used when you want to have some sort of hierarchal representation of your data (ie drill down).  They work using a stack of UIViewController subclasses. Every time you &#8220;drill down&#8221;, you simply add another view controller to the stack.  Then, the &#8220;back&#8221; logic is simply a matter of popping view controllers off of a stack.</p>
<p>At the bottom of the stack, there is the rootViewController which get set during initialization and can never be popped off.  At the top of the stack, is the current view controller who&#8217;s view is being displayed to the user.</p>
<p>Here is a code sample demonstrating how to push a view controller on to the navigation stack.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Initialize MyViewController object</span>
MyViewController <span style="color: #002200;">*</span>controller <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MyViewController alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MyViewController&quot;</span> 
                                                                   bundle<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #11740a; font-style: italic;">// Pushes MyViewController object on the navigation stack</span>
<span style="color: #002200;">&#91;</span>self.navigationController pushViewController<span style="color: #002200;">:</span>controller animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>controller release<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>In this example, we instantiate a new UIViewController subclass called MyViewController and push it on to the view controller stack.  One very important detail to point out is, you must do this from inside of a view controller that is contained inside of a navigation controller, otherwise the &#8220;self.navigationController&#8221; property will be nil.  navigationController is a property of every UIViewController subclass that gets set whenever it has been inserted into a UINavigationController.</p>
<p>Another thing to note is, we release the controller after pushing it on to the stack (prior to iOS5 with ARC). This is because the navigation controller will retain your view controller therefore preventing it from being released from memory.</p>
<p>The following code will pop the view controller off of the view stack with an animation.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>self.navigationController popViewControllerAnimated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Now we are going to see how UINavigationControllers are used in conjunction with UITableViewControllers.</p>
<h4>UITableViewController</h4>
<div id="attachment_3465" class="wp-caption alignnone" style="width: 169px"><a href="http://www.icodeblog.com/2011/10/11/back-to-basics-an-introduction-to-view-controllers/screen-shot-2011-10-11-at-11-35-44-am/" rel="attachment wp-att-3465"><img src="http://www.icodeblog.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-11-at-11.35.44-AM-159x300.png" alt="" title="Screen Shot 2011-10-11 at 11.35.44 AM" width="159" height="300" class="size-medium wp-image-3465" /></a><p class="wp-caption-text">UITableViewController</p></div>
<p>UITableViewControllers are quite possibly the most popular/common view controllers used in iOS.  They are perfect for displaying large amounts of data or any sort of form entry.</p>
<p>By default, a UITableViewController has a UITableView as it&#8217;s main view and serves as both the delegate and data source for this view.  What this means is, it is responsible for populating the table with data, configuring how the data is displayed, and determining what to do when the user interacts with the table (swipes, touches, etc&#8230;).</p>
<p>Let&#8217;s take a look at a simple UITableViewController.  Here is an init method initializing the data array to be displayed in the table view as well as the primary 3 data source methods.</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;">id</span><span style="color: #002200;">&#41;</span>initWithNibName<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>nibNameOrNil bundle<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSBundle</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>nibBundleOrNil <span style="color: #002200;">&#123;</span>
    self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super initWithNibName<span style="color: #002200;">:</span>nibNameOrNil bundle<span style="color: #002200;">:</span>nibBundleOrNil<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        self.title <span style="color: #002200;">=</span> NSLocalizedString<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Sites&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Sites&quot;</span><span style="color: #002200;">&#41;</span>;
        <span style="color: #11740a; font-style: italic;">// #1</span>
        _dataArray <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Reddit&quot;</span>,
                                                        <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;XKCD&quot;</span>,
                                                        <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;The Oatmeal&quot;</span>,
                                                        <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Hacker News&quot;</span>,
                                                        <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;iCodeBlog&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>numberOfSectionsInTableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// #2</span>
    <span style="color: #a61390;">return</span> <span style="color: #2400d9;">1</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView numberOfRowsInSection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>section <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// #3</span>
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>_dataArray count<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UITableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>CellIdentifier <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Cell&quot;</span>;
&nbsp;
    UITableViewCell <span style="color: #002200;">*</span>cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>tableView dequeueReusableCellWithIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>cell <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITableViewCell alloc<span style="color: #002200;">&#93;</span> initWithStyle<span style="color: #002200;">:</span>UITableViewCellStyleDefault reuseIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
        cell.accessoryType <span style="color: #002200;">=</span> UITableViewCellAccessoryDisclosureIndicator;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// #4</span>
    cell.textLabel.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>_dataArray objectAtIndex<span style="color: #002200;">:</span>indexPath.row<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">return</span> cell;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>As mentioned before, we are displaying a simple array of NSString objects in the table view.  This array gets initialized in #1 before the tableview is even displayed.  The next method in #2 returns the number of sections for the table.  In our case, we only need one section so we hard code the number 1 as the return value.</p>
<p>The code in #3 returns the number of cells in a given section.  Generally, this will mean the number of objects in your array.  So, we just return the count property of our dataArray.</p>
<p>Finally, the method in #4 builds the cell for a given row in a section, configures that cell, and returns it.  In our case, the only configuration we need to do is set the text property of the cell&#8217;s UITextLabel to the string in our array at the corresponding index.</p>
<p>These 3 methods are the absolute minimum required to use a UITableViewController and display its table.  There are quite a few more methods that you can implement related to the cell height, titles for sections, and more.  The last thing I want to show you is how to support basic user interaction.</p>
<p>There is only one method you need to implement to support taps on the cells.  Here is the sample code from above inside of didSelectRowAtIndexPath.</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>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView didSelectRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath
<span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Initialize MyViewController object</span>
    MyViewController <span style="color: #002200;">*</span>controller <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MyViewController alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MyViewController&quot;</span> 
                                                                       bundle<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">// Forward some data</span>
    controller.site <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>_dataArray objectAtIndex<span style="color: #002200;">:</span>indexPath.row<span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">// Pushes MyViewController object on the navigation stack</span>
    <span style="color: #002200;">&#91;</span>self.navigationController pushViewController<span style="color: #002200;">:</span>controller animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>controller release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Now when the user taps a row, it will loading up a MyViewController object, pass along the information about the cell tapped and push it on to the view stack.  One thing to note here is, this code assumes that the UITableViewController class presented above is inside of a UINavigationController. </p>
<h4>UITabBarController</h4>
<div id="attachment_3466" class="wp-caption alignnone" style="width: 169px"><a href="http://www.icodeblog.com/2011/10/11/back-to-basics-an-introduction-to-view-controllers/screen-shot-2011-10-11-at-11-36-03-am/" rel="attachment wp-att-3466"><img src="http://www.icodeblog.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-11-at-11.36.03-AM-159x300.png" alt="" title="Screen Shot 2011-10-11 at 11.36.03 AM" width="159" height="300" class="size-medium wp-image-3466" /></a><p class="wp-caption-text">UITabBarController</p></div>
<p>The last controller we are going to discuss in this post is the UITabBarController.  As you may have seen in many applications, a tab bar separates out view logic into multiple &#8220;tabs&#8221; and switches between them when the user taps on each one.  Each tab represents a different view controller that could be any of the types above.  As a newer developer, TabBarControllers are a little tricky to implement manually, so I&#8217;d suggest starting your project using &#8220;Apple&#8217;s Tab Bar Application&#8221; template file. This will provide you with a simple tab bar application with two sample tabs.</p>
<p>We are going to walk through the code generated from the iOS 5 template that details how a tab bar is constructed.</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;">BOOL</span><span style="color: #002200;">&#41;</span>application<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application didFinishLaunchingWithOptions<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>launchOptions <span style="color: #002200;">&#123;</span>
    self.window <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIWindow alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span> bounds<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">// #1</span>
    UIViewController <span style="color: #002200;">*</span>viewController1 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>FirstViewController alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;FirstViewController&quot;</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
    UIViewController <span style="color: #002200;">*</span>viewController2 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>SecondViewController alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;SecondViewController&quot;</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">// #2</span>
    self.tabBarController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITabBarController alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">// #3</span>
    self.tabBarController.viewControllers <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> arrayWithObjects<span style="color: #002200;">:</span>viewController1, viewController2, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">// #4</span>
    self.window.rootViewController <span style="color: #002200;">=</span> self.tabBarController;
    <span style="color: #002200;">&#91;</span>self.window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>The code here is actually pretty straight forward.  #1 initializes both of the view controllers we want to display in 2 separate tabs.  Don&#8217;t worry about setting their title and tab bar icon now, I will get to that in a moment.</p>
<p>Now, in #2 we initialize the tab bar controller.  Unlike the UITableViewController, we don&#8217;t need to make our own subclass.  It is fine to just let the app delegate manage an instance of the tab bar controller.  </p>
<p>The code in #3 is where we set the view controllers of the tab bar controller.  It should be clear now how easy it is to add more &#8220;tabs&#8221; to you your application. </p>
<p>Finally, #4 adds the tab bar controller to the window displaying it to the user.</p>
<p>Let&#8217;s take a quick look at the code in the initWithNibName method of FirstViewController in order to see how the title and image are set for that controller.</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;">id</span><span style="color: #002200;">&#41;</span>initWithNibName<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>nibNameOrNil bundle<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSBundle</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>nibBundleOrNil
<span style="color: #002200;">&#123;</span>
    self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super initWithNibName<span style="color: #002200;">:</span>nibNameOrNil bundle<span style="color: #002200;">:</span>nibBundleOrNil<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        self.title <span style="color: #002200;">=</span> NSLocalizedString<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;First&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;First&quot;</span><span style="color: #002200;">&#41;</span>;
        self.tabBarItem.image <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;first&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Pretty simple right?  Every UIViewController subclass has a title and tabBarItem property.  That way, it knows what to display if you place it inside of a UITabBarController.</p>
<h4>Conclusion</h4>
<p>This wraps up our very surface level introduction to UIViewControllers.  I have zipped both of the sample projects used here and you can download them <a href='http://www.icodeblog.com/2011/10/11/back-to-basics-an-introduction-to-view-controllers/viewcontrollers/' rel='attachment wp-att-3479'>here</a>.</p>
<p>If you have any questions or comments, please feel free to leave them here or write them to me on <a href="http://twitter.com/brandontreb">Twitter</a>.</p>
<p>Happy iCoding!</p>
<p><span style="font-family: 'Lucida Grande';"><strong><span style="font-weight: normal;"><span style="font-family: arial, verdana, tahoma, sans-serif; font-size: 13px; line-height: 20px;"><em>This post is part of an iOS development series called Back To Basics.  You can keep up with this series through the <a style="text-decoration: none; color: #004199; padding: 0px; margin: 0px;" href="http://www.icodeblog.com/2011/07/12/iphone-development-back-to-basics/">table of contents</a>, <a style="text-decoration: none; color: #004199; padding: 0px; margin: 0px;" href="http://www.icodeblog.com/tag/b2b/feed/">RSS feed</a>, or <a style="text-decoration: none; color: #004199; padding: 0px; margin: 0px;" href="https://twitter.com/#!/brandontreb">Twitter</a>.</em></span></span></strong></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.icodeblog.com/2011/10/11/back-to-basics-an-introduction-to-view-controllers/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Subclassing Class Clusters</title>
		<link>http://www.icodeblog.com/2011/10/10/subclassing-class-clusters/</link>
		<comments>http://www.icodeblog.com/2011/10/10/subclassing-class-clusters/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 16:51:18 +0000</pubDate>
		<dc:creator>Collin</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Intermediate]]></category>

		<guid isPermaLink="false">http://www.icodeblog.com/?p=3434</guid>
		<description><![CDATA[Subclassing is something any object oriented programmer is pretty familiar with. Common examples would be that a square is a subclass of a rectangle. This means that all squares are rectangles, and hold all properties of rectangles but not all rectangles are squares. Squares are a special subset of rectangles that have both sides being the same length. Objective-C has become so evolved that you may use this simplified conceptualization for all objects in Objective-C when in reality there is  ...]]></description>
			<content:encoded><![CDATA[<p>Subclassing is something any object oriented programmer is pretty familiar with. Common examples would be that a square is a subclass of a rectangle. This means that all squares are rectangles, and hold all properties of rectangles but not all rectangles are squares. Squares are a special subset of rectangles that have both sides being the same length. Objective-C has become so evolved that you may use this simplified conceptualization for all objects in Objective-C when in reality there is much more complexity behind the scenes in some of the most common Objective-C objects. </p>
<p>For certain Objective-C objects such as NSString, NSNumber, NSArray, NSData, NSDictionary a design pattern called <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html%23//apple_ref/doc/uid/TP40002974-CH4-SW34">Class Clustering</a> is utilized to present a public facing class to represent a collection of classes used behind the scenes. While this ends up creating some really powerful objects in the default Objective-C API, it presents some challenges to subclassing. Apple speaks to the challenges in subclassing the abstract class superclass representing a class cluster. When doing this a class must:</p>
<li>Be a subclass of the clusterâ€™s abstract superclass</li>
<li>Declare its own storage</li>
<li>Override all initializer methods of the superclass</li>
<li>Override the superclassâ€™s primitive methods</li>
<p>This list of tasks can seem a little overwhelming at first but it is pretty simple once you get into it. Today we are going to subclass NSString. The example we will make will encrypt a string upon initialization, the reason we want this to be a subclass rather than a category is that we want to be able to distinguish encrypted NSString object types from non encrypted object types.</p>
<h4>ICBEncryptedString.h</h4>
<p>Below is the our encrypted string object header. As you can see we are indeed subclassing the cluster&#8217;s abstract super class, in the case NSString. We are also declaring our own storage there with out NSString backing store instance variable. The great thing about this abstract parent class subclassing is that you can still use the type you are most used to as your backing store. If speed or memory was important to you here, you could also implement it with more lightweight C based structures as well. With that done we declare a new special class level initializer and override initWithString:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;Foundation/Foundation.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> ICBEncryptedString <span style="color: #002200;">:</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>_backingStore;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>encryptedStringWithString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #a61390;">string</span>;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #a61390;">string</span>;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<h4>ICBEncryptedString.m</h4>
<p>According to our to do list the next thing we need to do is override all initializer methods of the super. This would be very annoying to do for NSString so I have done it with 2 specific methods that I will always use when initializing ICBEncryptedString&#8217;s. So in our initializer here we simply take he string provided to us, SHA1 it, and then set our _backingStore NSString instance variable to the now encryptedString. The only remaining thing to do is override the superclass&#8217;s primitive method. NSString&#8217;s documentation tells us that the required primitive methods to override are length and characterAtIndex:, essentially, every other instance method for NSString relies on these methods as their backing. With this done we now have a distinguishable Encrypted String class that has all of the abilities of NSString but does encrypting for us on initialization. Check out the class implementation below. </p>
<p>You can find the NSString category for SHA1 at the awesome new site <a href="http://iosboilerplate.com/">iOS Boiler Blate</a></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;ICBEncryptedString&quot;</span>
<span style="color: #6e371a;">#import &quot;NSString+Helper.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> ICBEncryptedString
&nbsp;
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>encryptedString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #a61390;">string</span> <span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@&quot;</span>, <span style="color: #002200;">&#91;</span><span style="color: #a61390;">string</span> SHA1<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>encryptedStringWithString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #a61390;">string</span> <span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>ICBEncryptedString alloc<span style="color: #002200;">&#93;</span> initWithString<span style="color: #002200;">:</span><span style="color: #a61390;">string</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #a61390;">string</span> <span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self init<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
&nbsp;
        _backingStore <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>ICBEncryptedString encryptedString<span style="color: #002200;">:</span><span style="color: #a61390;">string</span><span style="color: #002200;">&#93;</span> copy<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<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>
&nbsp;
    <span style="color: #002200;">&#91;</span>_backingStore release<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>NSUInteger<span style="color: #002200;">&#41;</span>length <span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>_backingStore length<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>unichar<span style="color: #002200;">&#41;</span>characterAtIndex<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSUInteger<span style="color: #002200;">&#41;</span>index <span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>_backingStore characterAtIndex<span style="color: #002200;">:</span>index<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Follow me on Twitter <a href="http://www.twitter.com/cruffenach">@cruffenach</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.icodeblog.com/2011/10/10/subclassing-class-clusters/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dynamically Controlling Your Application From The Web</title>
		<link>http://www.icodeblog.com/2011/09/30/dynamically-controlling-your-application-from-the-web/</link>
		<comments>http://www.icodeblog.com/2011/09/30/dynamically-controlling-your-application-from-the-web/#comments</comments>
		<pubDate>Fri, 30 Sep 2011 20:21:29 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.icodeblog.com/?p=3421</guid>
		<description><![CDATA[Often times you find yourself in a situation where you might want to control your application remotely.  You may want to enable/disable features at a certain time, push messages to all of your users, or do some cross promotion whenever you launch a new application.  All of this can easily be done with a little JSON and some simple web interface coding.

&#160;
In this tutorial, I will show you how to use ASIHTTPRequest along with JSONKIT to fetch, parse,  ...]]></description>
			<content:encoded><![CDATA[<p>Often times you find yourself in a situation where you might want to control your application remotely.  You may want to enable/disable features at a certain time, push messages to all of your users, or do some cross promotion whenever you launch a new application.  All of this can easily be done with a little JSON and some simple web interface coding.</p>
<p><img src="http://f.cl.ly/items/230o40381f3M1u2M0e35/Screen%20Shot%202011-09-30%20at%202.12.47%20PM.png" width="250"></p>
<div style="clear:both">&nbsp;</div>
<p>In this tutorial, I will show you how to use ASIHTTPRequest along with JSONKIT to fetch, parse, and interpret remote JSON that will ultimately change how our application behaves. For this example, we are going to make a simple &#8220;nag&#8221; popup that will nag the user to download your latest application.  When you set a remote flag to true, all users will see the popup every time they launch the application.  The popup will also display a dynamic message from the web and link to a location specified in the JSON.</p>
<h4>1. The JSON</h4>
<p>First, let&#8217;s chat a little bit about the JSON we will be using.  Here&#8217;s what it will look like:</p>

<div class="wp_syntax"><div class="code"><pre class="json" style="font-family:monospace;">{
    &quot;nag&quot;: true,
    &quot;message&quot;: &quot;Check out Smart Lockscreen Creator!&quot;,
    &quot;url&quot;: &quot;http://itunes.apple.com/us/app/smart-lockscreen-creator/id419890996?mt=8&quot;
}</pre></div></div>

<p>The field names should be pretty self explanatory.  We will use JSON kit to parse these fields into an NSDictionary.</p>
<h4>2. The Libraries</h4>
<p>As mentioned before, we will be using 2 libraries to get the job done.</p>
<ul>
<li><a href="http://github.com/pokeb/asi-http-request/">ASIHTTPRequest</a> ASIHTTPRequest is an easy to use wrapper around the CFNetwork API that makes some of the more tedious aspects of communicating with web servers easier.</li>
<li><a href="https://github.com/johnezang/JSONKit">JSONKit</a> &#8211; A JSON Parser written in C with an Objective-C wrapper.</li>
</ul>
<p>Make sure you download their source and follow each of their instructions for setting up your project to use them.  JSONKit is pretty much drag in the source and you are good to go.  ASI has a few framework dependancies that you are going to have to work out.  The instructions for setting it up are <a href="http://allseeing-i.com/ASIHTTPRequest/Setup-instructions">here</a>.</p>
<h4>3. The Code &#8211; Download And Parse</h4>
<p>You can add the code to fetch and control your application wherever you see fit, however I have added mine to the application&#8217;s delegate method.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">    <span style="color: #11740a; font-style: italic;">// 1. Fetch out to the web</span>
    <span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>url <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://f.cl.ly/items/2y141v3O0G2e2Y2W3P24/alert.json&quot;</span><span style="color: #002200;">&#93;</span>;
    ASIHTTPRequest <span style="color: #002200;">*</span>request <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>ASIHTTPRequest requestWithURL<span style="color: #002200;">:</span>url<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// 2. Completion block</span>
    <span style="color: #002200;">&#91;</span>request setCompletionBlock<span style="color: #002200;">:^</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>responseString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>request responseString<span style="color: #002200;">&#93;</span>;
        <span style="color: #11740a; font-style: italic;">// 3. parse the response</span>
        <span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>responseDict <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>responseString objectFromJSONString<span style="color: #002200;">&#93;</span>;
&nbsp;
        <span style="color: #11740a; font-style: italic;">// 4. pull out data</span>
        <span style="color: #a61390;">BOOL</span> nag <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>responseDict objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;nag&quot;</span><span style="color: #002200;">&#93;</span> boolValue<span style="color: #002200;">&#93;</span>;
        <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>message <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>responseDict objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;message&quot;</span><span style="color: #002200;">&#93;</span>;
        self.nagURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>responseDict objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;url&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
        <span style="color: #11740a; font-style: italic;">// 5. If nag is true, then show the alert</span>
        <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>nag<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            UIAlertView <span style="color: #002200;">*</span>alert <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIAlertView alloc<span style="color: #002200;">&#93;</span> initWithTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Message&quot;</span> 
                                                             message<span style="color: #002200;">:</span>message 
                                                            delegate<span style="color: #002200;">:</span>self 
                                                   cancelButtonTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Cancel&quot;</span> 
                                                   otherButtonTitles<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Go&quot;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
            <span style="color: #002200;">&#91;</span>alert show<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">// 6. Start the request</span>
    <span style="color: #002200;">&#91;</span>request startAsynchronous<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>In #1, we fetch out to the web and pull down the json string that contains our configuration settings.  #2 sets the completion block for the request.  If you are unfamiliar with this pattern, the request fires off in a new thread and the block gets executed AFTER the request completes.  That way, we can keep all of our code in line rather than messing around with target and selector callbacks.</p>
<p>For #3, we are using JSONKit&#8217;s category on NSString that returns an NSDictionary representation of the JSON string. It couldn&#8217;t be easier.</p>
<p>Line #4 is where we extract the info from the dictionary and assign it to local variables.  We set the nagURL global property here as well.  The reason we must create a property for nagURL is we need to use it again in the delegate method for the UIAlertView in order to send the user to the url specified from the web.</p>
<p>Line #5 is where we check if nag is true and then show the alert.  Make sure to set the delegate to our calling class so that we can respond accordingly. </p>
<p>Finally, in #6, we start the request asynchronously.</p>
<p>The last thing to do is implement the delegate method  for the alert view.  It&#8217;s pretty straight forward:</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> alertView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIAlertView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>alertView didDismissWithButtonIndex<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>buttonIndex <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>buttonIndex <span style="color: #002200;">==</span> <span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span> openURL<span style="color: #002200;">:</span>self.nagURL<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>We simply check to see if the user pressed the &#8220;Go&#8221; button, if so, we send them to the URL specified by the nagURL property.</p>
<h4>Conclusion</h4>
<p>And there you have it.  A very simple example of how you can control some portion of your applicaiton&#8217;s functionality based on remote web data.  You could expand upon this in a number of ways including:</p>
<ul>
<li>Enabling/Disabling parts of the app</li>
<li>Loading &#8220;News&#8221; in some sort of ticker</li>
<li>Daily promotions</li>
<li>Promote new apps</li>
<li>Daily content (jokes, words, inspiration, scripture, etc&#8230;)</li>
</ul>
<p>If you have any questions or comments, you can leave the here or write me on Twitter.</p>
<p>The source project for this post is available <a href="http://cl.ly/0e282h0P230I1j1n2x0f">here</a>.</p>
<p>Happy iCoding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icodeblog.com/2011/09/30/dynamically-controlling-your-application-from-the-web/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

