<?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 &#187; Programming</title>
	<atom:link href="/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://icodeblog.com</link>
	<description>iPhone Programming Tutorials</description>
	<lastBuildDate>Tue, 19 Nov 2013 19:34:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>Code Snippet &#8211; Quickly Find The Documents Directory</title>
		<link>http://icodeblog.com/2009/09/09/code-snippet-quickly-find-the-documents-directory/</link>
		<comments>http://icodeblog.com/2009/09/09/code-snippet-quickly-find-the-documents-directory/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 14:54:18 +0000</pubDate>
		<dc:creator><![CDATA[brandontreb]]></dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[iPhone Coding]]></category>
		<category><![CDATA[iphone dev]]></category>
		<category><![CDATA[iphone documents]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[save files]]></category>

		<guid isPermaLink="false">http://icodeblog.com/?p=1295</guid>
		<description><![CDATA[As many of you may have seen by now, there are quite a few ways to find the documents directory on the iPhone.  For those of you who don&#8217;t know, the documents directory of an app is the location where you should save your application data.  While finding the documents directory is a trivial task, it is very important when coding most applications.  Apple has provided quite a few ways for resolving the path to this directory.
If  ...]]></description>
				<content:encoded><![CDATA[<p>As many of you may have seen by now, there are quite a few ways to find the documents directory on the iPhone.  For those of you who don&#8217;t know, the documents directory of an app is the location where you should save your application data.  While finding the documents directory is a trivial task, it is very important when coding most applications.  Apple has provided quite a few ways for resolving the path to this directory.</p>
<p>If you read through some of Apple&#8217;s sample code, you will see their code to do this is generally 3 or 4 lines long.  This seems like a lot of code to perform such a simple task.  Here is a nice one-liner for you to use in your applications.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span> docs <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>NSHomeDirectory<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>
						   stringByAppendingPathComponent<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Documents&quot;</span><span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>It&#8217;s clean and concise.  Happy iCoding!</p>
]]></content:encoded>
			<wfw:commentRss>http://icodeblog.com/2009/09/09/code-snippet-quickly-find-the-documents-directory/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>NSTimer: The Poor Man&#8217;s Threading &#8211; Code Snapshot</title>
		<link>http://icodeblog.com/2009/07/23/nstimer-the-poor-mans-threading-code-snapshot/</link>
		<comments>http://icodeblog.com/2009/07/23/nstimer-the-poor-mans-threading-code-snapshot/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 18:28:26 +0000</pubDate>
		<dc:creator><![CDATA[Collin]]></dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[NSTimer]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://icodeblog.com/?p=1152</guid>
		<description><![CDATA[Introduction
Hey guys. So usually the posts we put up here involve screencasts and presentations, but we are going to start also posting small less time consuming pieces for the site. Today I bring to you a small project involving NSTimers. Today we are going to build an app that represents a horse race. We will create a view with 6 small UIView squares with a blue background at the bottom of the screen, we will use a timer to move  ...]]></description>
				<content:encoded><![CDATA[<h1><span style="color: #ff6600;">Introduction</span></h1>
<p>Hey guys. So usually the posts we put up here involve screencasts and presentations, but we are going to start also posting small less time consuming pieces for the site. Today I bring to you a small project involving NSTimers. Today we are going to build an app that represents a horse race. We will create a view with 6 small UIView squares with a blue background at the bottom of the screen, we will use a timer to move a random one of them forward a random amount of distance. Let&#8217;s get started!</p>
<p><a href="/wp-content/uploads/2009/07/Picture-162.png"><img class="aligncenter size-full wp-image-1164" title="Picture 16" src="/wp-content/uploads/2009/07/Picture-162.png" alt="Picture 16" width="351" height="693" /></a></p>
<h1><span style="color: #ff6600;">Source</span></h1>
<p>You can get the source here: <a href="/wp-content/uploads/2009/07/NSTimerDemo2.zip">NSTimerDemo</a></p>
<h1><span style="color: #ff6600;">Steps</span></h1>
<h3><span style="color: #ff6600;">Step 1<br />
</span></h3>
<p>Create a view based application in xCode. Call it whatever.</p>
<h3><span style="color: #ff6600;">Step 2<br />
</span></h3>
<p>In your view controller class header file add:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSTimer</span> <span style="color: #002200;">*</span>myTimer;</pre></td></tr></table></div>

<h3><span style="color: #ff6600;">Step 3<br />
</span></h3>
<p>In your view controller class, uncomment out the viewDidLoad method and fill in the following code:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>viewDidLoad
<span style="color: #002200;">&#123;</span>
      <span style="color: #002200;">&#91;</span>super viewDidLoad<span style="color: #002200;">&#93;</span>;
&nbsp;
      CGRect workingFrame;
      workingFrame.origin.x <span style="color: #002200;">=</span> <span style="color: #2400d9;">15</span>;
      workingFrame.origin.y <span style="color: #002200;">=</span> <span style="color: #2400d9;">400</span>;
      workingFrame.size.width <span style="color: #002200;">=</span> <span style="color: #2400d9;">40</span>;
      workingFrame.size.height <span style="color: #002200;">=</span> <span style="color: #2400d9;">40</span>;
&nbsp;
      <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 <span style="color: #002200;">&amp;</span>lt; <span style="color: #2400d9;">6</span>; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span>
      <span style="color: #002200;">&#123;</span>
           UIView <span style="color: #002200;">*</span>myView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>workingFrame<span style="color: #002200;">&#93;</span>;
           <span style="color: #002200;">&#91;</span>myView setTag<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span>;
           <span style="color: #002200;">&#91;</span>myView setBackgroundColor<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIColor blueColor<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
           workingFrame.origin.x <span style="color: #002200;">=</span> workingFrame.origin.x <span style="color: #002200;">+</span> workingFrame.size.width <span style="color: #002200;">+</span> <span style="color: #2400d9;">10</span>;
           <span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span>myView<span style="color: #002200;">&#93;</span>;
      <span style="color: #002200;">&#125;</span>
&nbsp;
      myTimer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSTimer</span> scheduledTimerWithTimeInterval<span style="color: #002200;">:</span>.1 target<span style="color: #002200;">:</span>self selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>moveACar<span style="color: #002200;">&#41;</span> userInfo<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> repeats<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<h3><span style="color: #ff6600;">Step 4<br />
</span></h3>
<h3><span style="color: #ff6600;"> </span></h3>
<p>In your view controller class, add the following method:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>moveACar
<span style="color: #002200;">&#123;</span>
      <span style="color: #a61390;">int</span> r <span style="color: #002200;">=</span> <span style="color: #a61390;">rand</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">%</span> <span style="color: #2400d9;">6</span>;
      NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;My number is %d&quot;</span>, r<span style="color: #002200;">&#41;</span>;
&nbsp;
      <span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span>UIView <span style="color: #002200;">*</span>aView <span style="color: #a61390;">in</span> <span style="color: #002200;">&#91;</span>self.view subviews<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
      <span style="color: #002200;">&#123;</span>
           <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>aView tag<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> r<span style="color: #002200;">&#41;</span>
           <span style="color: #002200;">&#123;</span>
                <span style="color: #a61390;">int</span> movement <span style="color: #002200;">=</span> <span style="color: #a61390;">rand</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">%</span> <span style="color: #2400d9;">100</span>;
                CGRect workingFrame <span style="color: #002200;">=</span> aView.frame;
                workingFrame.origin.y <span style="color: #002200;">=</span> workingFrame.origin.y <span style="color: #002200;">-</span> movement;
&nbsp;
                <span style="color: #002200;">&#91;</span>UIView beginAnimations<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> context<span style="color: #002200;">:</span><span style="color: #a61390;">NULL</span><span style="color: #002200;">&#93;</span>;
                <span style="color: #002200;">&#91;</span>UIView setAnimationDuration<span style="color: #002200;">:</span>.2<span style="color: #002200;">&#93;</span>;
                <span style="color: #002200;">&#91;</span>aView setFrame<span style="color: #002200;">:</span>workingFrame<span style="color: #002200;">&#93;</span>;
                <span style="color: #002200;">&#91;</span>UIView commitAnimations<span style="color: #002200;">&#93;</span>;
&nbsp;
                <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>workingFrame.origin.y <span style="color: #002200;">&amp;</span>lt; <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>
                <span style="color: #002200;">&#123;</span>
                    <span style="color: #002200;">&#91;</span>myTimer invalidate<span style="color: #002200;">&#93;</span>;
                <span style="color: #002200;">&#125;</span>
           <span style="color: #002200;">&#125;</span>
      <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<h1><span style="color: #ff6600;">Conclusion</span></h1>
<p>So that is it. Timers are really cool and come in handy for all sorts of small problems in a project. Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://icodeblog.com/2009/07/23/nstimer-the-poor-mans-threading-code-snapshot/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>iPhone Programming Tutorial: Integrating Twitter Into Your iPhone Applications</title>
		<link>http://icodeblog.com/2009/07/09/integrating-twitter-into-your-applications/</link>
		<comments>http://icodeblog.com/2009/07/09/integrating-twitter-into-your-applications/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 18:23:03 +0000</pubDate>
		<dc:creator><![CDATA[brandontreb]]></dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[iphone twitter]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[twitter iphone tutorial]]></category>

		<guid isPermaLink="false">http://icodeblog.com/?p=1080</guid>
		<description><![CDATA[<a href="/wp-content/uploads/2009/07/screenshot_121.png"></a>
If you are a developer (which you most likely are if you are reading this) you probably have (or should have) a Twitter account.  With Twitter getting so much attention lately, you would be crazy to not include some sort of Twitter integration into your own iPhone application.
There are many ways applications can be made more social by including Twitter.  For example, you could make the application auto-tweet when you unlock a special item in a game,  ...]]></description>
				<content:encoded><![CDATA[<p><a href="/wp-content/uploads/2009/07/screenshot_121.png"><img class="aligncenter size-full wp-image-1090" title="screenshot_12" src="/wp-content/uploads/2009/07/screenshot_121.png" alt="screenshot_12" width="600" /></a></p>
<p>If you are a developer (which you most likely are if you are reading this) you probably have (or should have) a Twitter account.  With Twitter getting so much attention lately, you would be crazy to not include some sort of Twitter integration into your own iPhone application.</p>
<p>There are many ways applications can be made more social by including Twitter.  For example, you could make the application auto-tweet when you unlock a special item in a game, or beat it.  This lets all of their friends know they are playing your game and in turn gets you more exposure.  You could also use this as an idea for creating your own Twitter client (<a href="/2009/07/08/look-familiar/">don&#8217;t just submit my tutorial to the app store</a>).</p>
<p>Twitter has provided us with some very simple API&#8217;s to follow making it a snap to interface with them. I have started a series on my personal blog about <a href="http://brandontreb.com/objective-c-programming-tutorial-creating-a-twitter-client-part-1/">creating a Twitter client for the Mac</a> that we will be borrowing some code from.</p>
<p>One thing I want to note before starting is: I will be going rather quick through the tutorial when it comes to creating the interface and hooking up the IBOutlets.  If you need extended help on that, this is probably not the tutorial you want to start on. Read some of my previous tutorials and come back.</p>
<p>This basic tutorial will just show you how to post a status update to your Twitter. I will also show you how to create an app that run entirely in landscape mode. So it&#8217;s a two-fer.</p>
<p>Let&#8217;s get started&#8230;</p>
<h2>1. Create A View Based Application</h2>
<p style="text-align: center;"><a href="/wp-content/uploads/2009/07/screenshot_022.png"><img class="size-full wp-image-1084 aligncenter" title="screenshot_02" src="/wp-content/uploads/2009/07/screenshot_022.png" alt="screenshot_02" width="600" height="442" /></a></p>
<p style="text-align: left;">
<p style="text-align: left;">Name it something <strong>awesome</strong>. I called mine TwitUpdate (not awesome, I know).  The first thing we should do is create our IBOutets and IBActions. Now download the images for the tutorial and drag them into the <strong>Resources</strong> group inside of XCode.</p>
<ul>
<li><a href="/wp-content/uploads/2009/07/btn_update1.png"><img class="size-full wp-image-1093 alignnone" title="btn_update" src="/wp-content/uploads/2009/07/btn_update1.png" alt="btn_update" width="97" height="36" /></a></li>
<li><a href="/wp-content/uploads/2009/07/twit_background1.png"><img class="size-full wp-image-1094 alignnone" title="twit_background" src="/wp-content/uploads/2009/07/twit_background1.png" alt="twit_background" width="480" height="320" /></a></li>
</ul>
<p style="text-align: center;"><a href="/wp-content/uploads/2009/07/screenshot_041.png"><img class="size-full wp-image-1085 aligncenter" title="screenshot_04" src="/wp-content/uploads/2009/07/screenshot_041.png" alt="screenshot_04" width="188" height="341" /></a></p>
<h2 style="text-align: left;">2. Set up your IBoutlets and IBActions</h2>
<p style="text-align: left;">So open <strong>TwitUpdateViewController.h. </strong>And let&#8217;s add the following code:</p>
<p style="text-align: center;"><a href="/wp-content/uploads/2009/07/screenshot_181.png"><img class="size-full wp-image-1098 aligncenter" title="screenshot_18" src="/wp-content/uploads/2009/07/screenshot_181.png" alt="screenshot_18" width="445" height="223" /></a></p>
<p style="text-align: left;">You can omit the UIButton outlets if you would like.  I just like having them around in case we want to do anything with the button.  This is pretty straight forward, we have a UITextView to enter our Twitter status in. And an IBAction that gets called to post our Twitter status.  Don&#8217;t forget to synthesize these properties in <strong>TwitUpdateViewController.m</strong> or you will be smitten by the compiler.  One other thing you will see here is a UIActionSheet.  We will display this sheet as our &#8220;Loading&#8221; screen when posting a tweet.</p>
<h2 style="text-align: left;">3. Build The Interface</h2>
<p style="text-align: left;">Go ahead and open up <strong>TwitUpdateViewController.xib.</strong></p>
<p style="text-align: left;">So if you are wondering how to get Interface Builder in landscape mode, it&#8217;s actually quite simple.  It is not obvious however as it took me forever and a freakin day to figure it out.  There is a little arrow (as in the screenshot below) in the top right corner of the view.  Click it and the view will rotate to landscape mode.</p>
<p style="text-align: left;"><a href="/wp-content/uploads/2009/07/screenshot_151.png"><img class="aligncenter size-full wp-image-1092" title="screenshot_15" src="/wp-content/uploads/2009/07/screenshot_151.png" alt="screenshot_15" width="69" height="55" /></a></p>
<p style="text-align: left;">Now that your interface is in landscape mode, remove the <strong>Status Bar</strong>.  This is done by clicking on the view and setting the <strong>Status Bar</strong> drop down in the <strong>attributes inspector</strong> to <strong>none. </strong>This will just give you more screen real estate.</p>
<p style="text-align: left;">Now drag a UIImageView on your view and stretch it to fill the entire screen.  Set the <strong>Image</strong> attribute of the UIImageView to be <strong>twit_background.png </strong>and bask in the glory of my beautifully created interface!  Next, we need to add the UITextView.</p>
<p style="text-align: left;">Grab a UITextView and drag in on to the view and stretch it to fit just inside of the chat bubble.  Make sure to delete the lorem ipsum text inside.</p>
<p style="text-align: left;">The last interface element we need to add is the update button.  Drag a UIButton on to your view.  In the button&#8217;s attributes, set it&#8217;s type to custom and it&#8217;s image to <strong>btn_update.png.</strong> Make sure you drag the button to fit the update image. Your final interface should look like this</p>
<p style="text-align: left;"><a href="/wp-content/uploads/2009/07/screenshot_111.png"><img class="aligncenter size-full wp-image-1089" title="screenshot_11" src="/wp-content/uploads/2009/07/screenshot_111.png" alt="screenshot_11" width="480" height="322" /></a></p>
<p style="text-align: left;">Now, connect the <strong>twitterMessageText </strong>from File&#8217;s Owner to the UITextView and the <strong>updateButton </strong>to your custom button.  Also, be sure to connect the <strong>TouchUpInside</strong> method of the UIButton to the <strong>postTweet</strong> IBAction.  Here is a screenshot of what the connection properties should look like when you click on File&#8217;s owner.</p>
<p style="text-align: left;"><a href="/wp-content/uploads/2009/07/screenshot_081.png"><img class="aligncenter size-full wp-image-1087" title="screenshot_08" src="/wp-content/uploads/2009/07/screenshot_081.png" alt="screenshot_08" width="775" height="225" /></a></p>
<p style="text-align: left;">Now close Interface Builder.</p>
<h2 style="text-align: left;">4. Creating Our Twitter Request Class</h2>
<p style="text-align: left;">So, we will interface with Twitter using an NSMutableURL request and NSURLConnection.  You have two options at this juncture, you can either download the files below and add them to your project to use, or you can head on over to <a href="http://brandontreb.com/objective-c-programming-tutorial-creating-a-twitter-client-part-1/">http://brandontreb.com/objective-c-programming-tutorial-creating-a-twitter-client-part-1/</a> and learn how to create them yourself (recommended route).  I would explain it here, it&#8217;s just that I already wrote an in depth tutorial for it on my blog. This is now a tutorial scavenger hunt.</p>
<h3><span style="color: #ff0000;">3.1 Note: As pointed out, by teresa and Ivan in the comments , to get it working in 3.1 </span></h3>
<blockquote><p>just comment out the [newCredential release] in</p>
<p>In &#8211; (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge</p></blockquote>
<p>We were releasing this object too early and it was causing a crash</p>
<ul>
<li><a href="http://brandontreb.com/wp-content/uploads/2009/07/TwitterRequest.zip">twitterrequest.zip</a></li>
</ul>
<p>If you just want to complete this tutorial and move on, download the file above, unzip and drag the files into your project.  We need to add some code to these files in order to post a status update to Twitter.  So, open TwitterRequest.h and update the following code</p>
<p style="text-align: center;"><a href="/wp-content/uploads/2009/07/screenshot_161.png"><img class="size-full wp-image-1096 aligncenter" title="screenshot_16" src="/wp-content/uploads/2009/07/screenshot_161.png" alt="screenshot_16" width="672" height="414" /></a></p>
<p style="text-align: left;">We have added a Boolean that denotes whether or not we are making a HTTP POST request (Twitter uses both POST and GET).  Also, there is a string that will represent the POST request.  In our case, this will just get set to &#8220;status=foo&#8221; (foo being your status update).</p>
<p style="text-align: left;">Also, we have added a method signature to update your status.  It takes an NSString which is just the status text.  The other variables are explained in my tutorial on brandontreb.com.  Now, open up <strong>TwitterRequest.m</strong> and add the following code.</p>
<p style="text-align: center;"><a href="/wp-content/uploads/2009/07/screenshot_171.png"><img class="size-full wp-image-1097 aligncenter" title="screenshot_17" src="/wp-content/uploads/2009/07/screenshot_171.png" alt="screenshot_17" width="756" height="331" /></a></p>
<p style="text-align: left;">Ok, beginning with the status_update method.  This method looks very similar to our friends_timeline method with a few exceptions.  First, we set isPost = YES.  Next, we set the request body = &#8220;status=%@&#8221; where we set %@ to our status update.</p>
<p style="text-align: left;">Now, for some trickier code.  In the request method of our class, we need to add some code to do an HTTP POST (rather than a GET).  This is how we tell Twitter what to set our status to.  So, the first thing is to set the HTTPMethod for the request to POST.  Next, we have set the &#8220;Content-Type&#8221; field to let Twitter know what kind of data we are sending.  Following that, the body of the request is sent.  This is the actual data that Twitter will see.  Finally, we just tell the request how large (in bytes) our data is going to be.  If this is all foreign to you, I recommend you go read up on POST and GET.</p>
<p style="text-align: left;">Phew&#8230; Done with that.  Now for the final part of implementing our postTweet method.</p>
<h2 style="text-align: left;">5. PostTweet Method</h2>
<p style="text-align: left;">Open up TwitterUpdateViewController.m and add the following code.</p>
<p style="text-align: center;"><a href="/wp-content/uploads/2009/07/screenshot_201.png"><img class="size-full wp-image-1099 aligncenter" title="screenshot_20" src="/wp-content/uploads/2009/07/screenshot_201.png" alt="screenshot_20" width="705" height="339" /></a></p>
<p style="text-align: left;">Ok, not super complex as the TwitterRequest class does most of the heavy lifting.  As a reminder, the postTweet method gets called when you press the Update button.  The first thing we do here is build a new TwitterRequest object and set the username and password field.  Make sure you put in YOUR twitter username and password.  Next, we call the resignFirstResponder method on the UITextView.  This is to hide the keyboard.</p>
<p style="text-align: left;">Just so the user knows something is happening, we display a simple action sheet that has no buttons and says &#8220;Posting to Twitter&#8230;&#8221; . Finally, we call the statuses_update method in our TwitterRequest class.</p>
<p style="text-align: left;">The Twitter request class will then do some magic and eventually call the callback method that you specified (status_updateCallback) and send it the data that Twitter returned to us.  The first thing we do is dismiss the action sheet. Next, I am simply outputting the response from Twitter in to the terminal.</p>
<p style="text-align: left;">The response received from Twitter would need to be parsed and displayed or something but that&#8217;s for another tutorial.One thing to note, if you enter an invalid username or password, this app will just hang and say  &#8220;Posting to Twitter&#8221; forever.  You need to handle this in an error callback method. Again <a href="http://brandontreb.com/objective-c-programming-tutorial-creating-a-twitter-client-part-1/">described in the tutorial</a> in which we took the TwitterRequest code from.</p>
<h2 style="text-align: left;">6. Run The App In Landscape Mode</h2>
<p style="text-align: left;">The last part of this tutorial is to force the app to run in landscape mode as well as hide the status bar.  Open up TwitUpdate-Info.plist. Right click on the table and select &#8220;Add Row&#8221;. Select <strong>Initial interface orientation</strong> and set the value to Landscape (left or right).  Right click again and add <strong>Status bar is initially hidden</strong>. to hide the status bar.  It should now look like this.</p>
<p style="text-align: left;"><a href="/wp-content/uploads/2009/07/screenshot_211.png"><img class="size-full wp-image-1105 aligncenter" title="screenshot_21" src="/wp-content/uploads/2009/07/screenshot_211.png" alt="screenshot_21" width="418" height="56" /></a>We also need to update the TwitUpdateViewConroller.m file to respond to the interface rotations.  Uncomment the following method in <strong>TwitUpdateViewController.m</strong> and change it to say:</p>
<p style="text-align: center;"><a href="/wp-content/uploads/2009/07/screenshot_221.png"><img class="size-full wp-image-1106 aligncenter" title="screenshot_22" src="/wp-content/uploads/2009/07/screenshot_221.png" alt="screenshot_22" width="571" height="91" /></a></p>
<p style="text-align: left;">Just tells the the view to rotate when the iphone is rotated&#8230;</p>
<p style="text-align: left;">Well, I hope you have enjoyed this tutorial.  I hope to see some cool Twitter integration in all of your apps (feel free to comment and let me know how you have implemented it in your app).  You can always ask questions in the comments of the post or <a href="http://twitter.com/brandontreb">write me on twitter</a>.  And for lazy people <a href="/wp-content/uploads/2009/07/twitupdate1.zip">here is the source</a> (j/k).  Happy iCoding.</p>
<p style="text-align: left;">
]]></content:encoded>
			<wfw:commentRss>http://icodeblog.com/2009/07/09/integrating-twitter-into-your-applications/feed/</wfw:commentRss>
		<slash:comments>139</slash:comments>
		</item>
		<item>
		<title>iPhone Programming Tutorial &#8211; Creating a ToDo List Using SQLite Part 4</title>
		<link>http://icodeblog.com/2008/09/22/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-4/</link>
		<comments>http://icodeblog.com/2008/09/22/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-4/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 23:47:39 +0000</pubDate>
		<dc:creator><![CDATA[brandontreb]]></dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[iphone programming]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQLite]]></category>
		<category><![CDATA[sqlite3]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://icodeblog.com/?p=392</guid>
		<description><![CDATA[This is the final installment of our 4 part series of creating a Todo list for the iPhone.  In this tutorial, I will detail how to add and delete new todo objects from the SQLite database.  Make sure that you have completed the following tutorials before you begin this one:

<a title="Permanent Link to iPhone Programming Tutorial - Creating a ToDo List Using SQLite Part 1" rel="bookmark" href="/2008/08/19/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-1/">iPhone Programming Tutorial &#8211; Creating a ToDo List Using SQLite Part 1</a>
<a  ...]]></description>
				<content:encoded><![CDATA[<p style="text-align: left;">This is the final installment of our 4 part series of creating a Todo list for the iPhone.  In this tutorial, I will detail how to add and delete new todo objects from the SQLite database.  Make sure that you have completed the following tutorials before you begin this one:</p>
<ul style="text-align: left;">
<li><a title="Permanent Link to iPhone Programming Tutorial - Creating a ToDo List Using SQLite Part 1" rel="bookmark" href="/2008/08/19/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-1/">iPhone Programming Tutorial &#8211; Creating a ToDo List Using SQLite Part 1</a></li>
<li><a title="Permanent Link to iPhone Programming Tutorial - Creating a ToDo List Using SQLite Part 1" rel="bookmark" href="/2008/09/02/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-2/">iPhone Programming Tutorial &#8211; Creating a ToDo List Using SQLite Part 2</a></li>
<li><a href="/2008/09/10/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-3/">iPhone Programming Tutorial &#8211; Creating a ToDo List Using SQLite Part 3</a></li>
</ul>
<p style="text-align: left;">When you have completed this tutorial, you should have a main screen that looks something like this:</p>
<p style="text-align: left;"><a href="/wp-content/uploads/2008/09/mainscreen1.png"><img class="size-full wp-image-394 aligncenter" title="screenshot" src="/wp-content/uploads/2008/09/mainscreen1.png" alt="" width="386" height="742" /></a></p>
<p style="text-align: left;">Let&#8217;s get started&#8230;</p>
<p style="text-align: left;">The first thing we need to do is add the UIBarButtonItem items to the NavigationBar so that we get the &#8220;Edit&#8221; and &#8220;Add&#8221; button.  Open up <strong>RootViewController.m</strong> and add the following code to the <strong>viewDidLoad</strong> method.</p>
<p style="text-align: left;"><a href="/wp-content/uploads/2008/09/viewdidload1.png"><img class="size-full wp-image-396 aligncenter" title="viewdidload" src="/wp-content/uploads/2008/09/viewdidload1.png" alt="" width="500" height="107" /></a></p>
<p style="text-align: left;">The first thing we see is the line that sets the leftBarButtonItem to self.editButtonItem.  This automatically adds the &#8220;Edit&#8221; button to the NavigationController.  Also, it sets up the functionality that allows the &#8220;delete&#8221; buttons to be displayed when the button is pressed.  You can see this functionality if you do a &#8220;Build and Go&#8221; at this step.  Next, I have manually created a UIBarButtonItem and added it to the navigationbar.  This can be done in Interface Builder, but I wanted to show you how to do it manually and assign an action to it (I&#8217;m sure you will require this functionality in a future program).  Here is a break down of the parameters:</p>
<ul style="text-align: left;">
<li>initWithTitle &#8211; The text to be displayed on the button</li>
<li>style &#8211; How the button will look</li>
<li>target &#8211; The class object that handles the messages sent from this button</li>
<li>action &#8211; The method to be called when the button is passed.  We can use @selector and give it the name of the function to call.</li>
</ul>
<p style="text-align: left;">Finally, we assign this button to the rightBarButtonItem.  If you do a Build and Go, it should error since we haven&#8217;t created the addTodo method. We will do that in a bit.  Now, let&#8217;s create a method inside of our Todo object that will add new Todos to the database.</p>
<p style="text-align: left;">Open up <strong>Todo.h</strong> and add the following code:</p>
<p style="text-align: left;"><a href="/wp-content/uploads/2008/09/todo1.png"><img class="alignnone size-full wp-image-398" title="todo" src="/wp-content/uploads/2008/09/todo1.png" alt="" width="363" height="33" /></a></p>
<p style="text-align: left;">So in addition to the <strong>insertNewTodoIntoDatabase</strong> method, we also see the deleteFromDatabase method signature.  I have just added this so I don&#8217;t have to come back to it later.  We will be implementing this when I show you how to delete todos from the database.  One thing to note about the <strong>insertNewTodoIntoDatabase </strong>method is it has a &#8220;+&#8221; rather than a &#8220;-&#8221; sign.  This means that it is a static method.  Static methods are associated with the class not the instance meaning we can call this method without instanciating this class.  So we can do stuff like Todo.insertNewTodoIntoDatabase.  Now we will implement this method.</p>
<p style="text-align: left;">Before we can do this, we must declare a few more static sqlite3_statement&#8217;s.  Add the following statements to the top of <strong>Todo.m</strong></p>
<p style="text-align: left;"><a href="/wp-content/uploads/2008/09/todomstatic1.png"><img class="size-full wp-image-400 aligncenter" title="todomstatic" src="/wp-content/uploads/2008/09/todomstatic1.png" alt="" width="270" height="30" /></a></p>
<p style="text-align: left;">Nothing new here&#8230;Now implement the following method:</p>
<p style="text-align: left;"><a href="/wp-content/uploads/2008/09/todom31.png"><img class="size-full wp-image-399 aligncenter" title="todom3" src="/wp-content/uploads/2008/09/todom31.png" alt="" width="499" height="197" /></a></p>
<p style="text-align: left;">This is similar to our update method.  Notice that we are inserting default values into the database.  This is so we don&#8217;t run into any problems with null or nil values.  The most important part of this method is the fact that it returns the primary key of the newly created todo object.  This will be used later so we can immediately transition to the todo when the &#8220;Add&#8221; button is pressed.  The last thing we need to do to the todo object is update the dehydrate method so that the todoText gets saved if it gets changed.  Update the dehydrate method to look like this:</p>
<p style="text-align: left;"><a href="/wp-content/uploads/2008/09/dehydrate1.png"><img class="size-full wp-image-401 aligncenter" title="dehydrate" src="/wp-content/uploads/2008/09/dehydrate1.png" alt="" width="500" height="257" /></a></p>
<p style="text-align: left;">There are only a few minor changes here.  First we see the &#8220;text = ?&#8221; part added to the sql statement.  This is simply so we can update the text of the todo.  The other change is we bound the self.text property to the 1st question mark in the sql statement.  One thing to notice is we call [self.text UTF8String].  This is because sqlite3_bind_text takes a (char *).  This will convert an NSString to an acceptable format.</p>
<p style="text-align: left;">Now we need to add a method inside of our RootViewController to add a todo.  This is the method that will be called when the user presses the &#8220;Add&#8221; button.  Inside of RootViewController.m add the following code:</p>
<p><a href="/wp-content/uploads/2008/09/1-rootviewcontroller1.png"><img class="size-full wp-image-422 aligncenter" title="1-rootviewcontroller" src="/wp-content/uploads/2008/09/1-rootviewcontroller1.png" alt="" width="500" height="179" /></a></p>
<p style="text-align: left;">First, we get a reference to the appDelegate object.  This is because we need to call its addTodo method.  Next, we instantiate the TodoViewController if it has not already been instantiated.  We need this around because we will push it on to the view stack and transition to it after we create our new todo object.  After this is done, we call the addTodo method of the appDelegate.  It will return the newly created todo object and the view will be transitioned to its detail screen in order to update its details.  Now we need to implement the method addTodo inside of our appDelegate.  Open up todoAppDelegate.h and add the following code to create the method signature.</p>
<p style="text-align: center;"><a href="/wp-content/uploads/2008/09/2-appdelegateh1.png"><img class="size-full wp-image-423 aligncenter" title="2-appdelegateh" src="/wp-content/uploads/2008/09/2-appdelegateh1.png" alt="" width="107" height="18" /></a></p>
<p style="text-align: left;">
<p style="text-align: left;">Now, let&#8217;s implement this method.  Open up todoAppDelegate.m and add the following code:</p>
<p style="text-align: left;">
<p style="text-align: left;"><a href="/wp-content/uploads/2008/09/3-appdelegatem1.png"><img class="size-full wp-image-424 aligncenter" title="3-appdelegatem" src="/wp-content/uploads/2008/09/3-appdelegatem1.png" alt="" width="500" height="101" /></a></p>
<p style="text-align: left;">
<p>First, we are calling the insertNewTodoIntoDatabase method of the Todo object.  Notice that we are simply calling the method without first building an instance of a todo object.  As I said in tutorial 3, this is because that method is static and gets called without building an instance of the class.  Next, we insatiate the todo object that was just created by calling its initWithPrimaryKey method.  This will give us reference to the new todo object.  Finally, we append this todo to the end of our todos array.  Since our UITableView is updated with this array, it will automatically include the new todo object.  The last line just returns this todo object.</p>
<p>Remember is the last tutorial we made it so the users could update the status and the priority of a todo?  Well, now we also need to give them the ability to update the text of the todo.  So open up TodoViewController.h and add the following code:</p>
<p style="text-align: center;">
<p><a href="/wp-content/uploads/2008/09/5-todoviewcontrollerh1.png"><img class="alignnone size-full wp-image-425" title="5-todoviewcontrollerh" src="/wp-content/uploads/2008/09/5-todoviewcontrollerh1.png" alt="" width="430" height="271" /></a><a href="/wp-content/uploads/2008/09/5-todoviewcontrollerh1.png"><br />
</a></p>
<p style="text-align: left;">
<p>Ok, so I&#8217;m guessing you are wondering why the UITextView for the todoText object has been changed to a UITextField.  Well, I will tell you.  UITextView doesn&#8217;t have the methods that we need to save the text with our current design.  We will also be changing this on our Interface inside of Interface Builder.  So for now, just believe me and anywhere it says UITextView, change it to UITextField.  The only additional code we added here is the method signature for the updateText method.  It&#8217;s an IBAction that will get called when the user presses the &#8220;Done&#8221; button on the keyboard after setting the text for the todo.  Next, we need to implement this method.  Open up TodoViewController.m and add the following code:</p>
<p style="text-align: center;"><a href="/wp-content/uploads/2008/09/5-todoviewcontrollerm1.png"><img class="size-full wp-image-426 aligncenter" title="5-todoviewcontrollerm" src="/wp-content/uploads/2008/09/5-todoviewcontrollerm1.png" alt="" width="245" height="53" /></a></p>
<p style="text-align: left;">All this does is update the text of the todo to the text that the user entered inside of the UITextField.  The last thing we need to do in order to add a todo is to replace the UITextView with a UITextField and connect it to our updateText method.  Double click on your TodoViewController.xib file to open it in Interface Builder.</p>
<p>Now click on the UITextView on your interface and press the delete key on your keyboard to delete it.  Now, drag a UITextField from the library and drop it onto your interface.  Resize it to fit.  When you have completed that, your interface should look something like this:</p>
<p style="text-align: center;"><a href="/wp-content/uploads/2008/09/6-interfacebuilder1.png"><img class="size-full wp-image-427 aligncenter" title="6-interfacebuilder" src="/wp-content/uploads/2008/09/6-interfacebuilder1.png" alt="" width="320" height="502" /></a></p>
<p style="text-align: left;">Now we need to connect this component.  Make sure it is selected and click Tools -&gt; Connections Inspector to open up the connections inspector.  Drag from the circle next to the method &#8220;Did End On Exit&#8221; to the &#8220;File&#8217;s Owner&#8221; object.  The words udpateText should pop up.  Click on them to make the connection.  Next, click in the circle next to &#8220;New Referencing Outlet&#8221; and drag it to the &#8220;File&#8217;s Owner&#8221; object.  Select todoText  when it pops up.  The Connections Inspector should look like this:</p>
<p style="text-align: center;"><a href="/wp-content/uploads/2008/09/12-ib1.png"><img class="size-full wp-image-434 aligncenter" title="12-ib" src="/wp-content/uploads/2008/09/12-ib1.png" alt="" width="287" height="708" /></a></p>
<p>Now we are done with Interface Builder.  Go ahead and close it.  We are now able to add todos.  The last thing we need to do is give the ability to delete todos from the list as well as our database.  This is all done in code, and we won&#8217;t need interface builder for this.</p>
<p>Let&#8217;s start by adding the methods to the appDelegate to handle the deletion of todos.  Open up todoAppDelegate.h and add the following code:</p>
<p style="text-align: center;"><a href="/wp-content/uploads/2008/09/7-appdelegateh1.png"><img class="alignnone size-full wp-image-428" title="7-appdelegateh" src="/wp-content/uploads/2008/09/7-appdelegateh1.png" alt="" width="194" height="16" /></a></p>
<p style="text-align: left;">All we see here is a signature for the removeTodo method.  Also, be sure to add a #import &#8220;Todo.h&#8221; statement to the top of this file so that we can interface with the todo objects. Now let&#8217;s implement the removeTodo method.  Open up todoAppDelegate.m and add the following code:</p>
<p style="text-align: center;"><a href="/wp-content/uploads/2008/09/8-appdelegatem1.png"><img class="size-full wp-image-429 aligncenter" title="8-appdelegatem" src="/wp-content/uploads/2008/09/8-appdelegatem1.png" alt="" width="308" height="119" /></a></p>
<p style="text-align: left;">The first line looks up the todo in the todos NSArray.  It returns the index in the array of the todo to be deleted.  Then, we call the deleteFromDatabase method on the todo object and then remove it from the todos array.  Since the UITableView is updated via this array, it will automatically remove the todo without any additional code on our part.</p>
<p>Now, let&#8217;s create the removeTodo method for the todo object. We have already written the method signature in Todo.h in a previous step, so open up Todo.m and add the following code:</p>
<p style="text-align: center;"><a href="/wp-content/uploads/2008/09/10-todom1.png"><img class="size-full wp-image-431 aligncenter" title="10-todom" src="/wp-content/uploads/2008/09/10-todom1.png" alt="" width="500" height="182" /></a></p>
<p style="text-align: left;">Remember the delete_statement variable is a static sqlite3_stmt that we declared in a previous step.  First, we check to see if it is nil.  If it is we compile the statement using the sqlite3_prepare statement.  Next, we bind the primary key of the current todo to the &#8220;?&#8221; in the sqlite3 statement.  Next, we just step the statement to execute it and reset it.  The last thing we need to do to delete todos from the database is to specify what happens when the user presses the &#8220;delete&#8221; button.  Open up RootViewController.m and add the following code:</p>
<p style="text-align: center;"><a href="/wp-content/uploads/2008/09/11-rootviewcontroller11.png"><img class="size-full wp-image-432 aligncenter" title="11-rootviewcontroller1" src="/wp-content/uploads/2008/09/11-rootviewcontroller11.png" alt="" width="499" height="143" /></a></p>
<p style="text-align: left;">
<p style="text-align: left;">The first step (like the first step of many functions) is to get a reference to the appDelegate.  Next, we check to see if we are currently editing.  If so, call the removeTodo method on appDelegate.  The next line, removes the row from the UITableView at the given indexPath.</p>
<p>Now click Build and Go!  You should now be able to add and delete todo items from the database.  This concludes our four part series of creating a todo list for the iPhone.  As always, if you have any questions feel free to leave them in the comments section.  If you get lost at any time you can download the sample code <a href="/wp-content/uploads/2008/09/todo-part-41.zip">here</a>.</p>
<p>Happy iCoding!</p>
<p style="text-align: left;">
]]></content:encoded>
			<wfw:commentRss>http://icodeblog.com/2008/09/22/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-4/feed/</wfw:commentRss>
		<slash:comments>115</slash:comments>
		</item>
		<item>
		<title>iCodeBlog Launched</title>
		<link>http://icodeblog.com/2008/07/22/icodeblog-launched/</link>
		<comments>http://icodeblog.com/2008/07/22/icodeblog-launched/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 02:26:55 +0000</pubDate>
		<dc:creator><![CDATA[brandontreb]]></dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[iPhone Articles]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://icodeblog.com/?p=4</guid>
		<description><![CDATA[iphone 3g
Welcome to iCodeBlog!  This blog will mainly focus on iphone programming using the XCode environment.  I will be updating weekly with iphone programming tutorials, news, updates and related nerdy stuff.
A little bit about me&#8230;
I am a Computer Science student at the University of New Mexico and will be starting my senior year this fall. I became interested in iPhone development with the launch of the web applications and had Apple accept 3 of my web applications.   ...]]></description>
				<content:encoded><![CDATA[<div id="attachment_5" style="width: 510px" class="wp-caption aligncenter"><img class="size-full wp-image-5 transparent" title="iphone" src="/wp-content/uploads/2008/07/iphone1.png" alt="iphone 3g" width="500" height="338" /><p class="wp-caption-text">iphone 3g</p></div>
<p>Welcome to iCodeBlog!  This blog will mainly focus on iphone programming using the XCode environment.  I will be updating weekly with iphone programming tutorials, news, updates and related nerdy stuff.</p>
<p><strong>A little bit about me&#8230;</strong></p>
<p>I am a Computer Science student at the University of New Mexico and will be starting my senior year this fall. I became interested in iPhone development with the launch of the web applications and had Apple accept 3 of my web applications.  The <a title="iPhone Web App - Cost Per Square Foot" href="http://www.apple.com/webapps/calculate/costpersquarefootcalculator.html" target="_blank">Cost Per Square Foot Calculator</a>, the <a title="iPhone Web App - Daily Calorie Calculator" href="http://www.apple.com/webapps/calculate/dailycaloriecalculator.html" target="_blank">Daily Calorie Calculator</a> , and a Weight Watchers app that they later pulled due to copyright.</p>
<p>Since the launch of the app store, I have been spending countless hours learning and researching iPhone programming using XCode.  One huge issue I noticed is the extreme lack of iPhone Programming tutorials on the web.  The best I could find was some outdated Hello World tutorial on YouTube.  So, I have decided to create iCodeBlog to share the things that I learn along the way.  So be sure to check back often!</p>
]]></content:encoded>
			<wfw:commentRss>http://icodeblog.com/2008/07/22/icodeblog-launched/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
