<?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>SAOB &#124; Senseless Acts of Beauty &#187; iPhone Development</title>
	<atom:link href="http://www.saobart.com/category/iphonedev/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.saobart.com</link>
	<description>The Work, Blog, and Art of Christopher Beaven</description>
	<lastBuildDate>Sat, 29 May 2010 17:13:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>MD5 Hash in Objective-C</title>
		<link>http://www.saobart.com/md5-has-in-objective-c/</link>
		<comments>http://www.saobart.com/md5-has-in-objective-c/#comments</comments>
		<pubDate>Mon, 10 May 2010 00:54:23 +0000</pubDate>
		<dc:creator>Gravityone</dc:creator>
				<category><![CDATA[OSX Development]]></category>
		<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://www.saobart.com/?p=666</guid>
		<description><![CDATA[After too much time spent searching the web via Google and getting a bunch of half answers and unfinished code for, what I though should be a very simple problem, I decided to make this post about how to create an MD5 hash from a string in Objective-c. My pain began when I decided to [...]]]></description>
			<content:encoded><![CDATA[<p>After too much time spent searching the web via Google and getting a bunch of half answers and unfinished code for, what I though should be a very simple problem, I decided to make this post about how to create an MD5 hash from a string in Objective-c.<span id="more-666"></span></p>
<p>My pain began when I decided to learn objective-c to build an OSX application using the <a title="the remember the milk api REST informational page" href="http://www.rememberthemilk.com/services/api/">Remember The Milk API</a> and after a bit of reading over their documentation realizing that the authorization can be a bit complex. I know that for some objective-c maybe as easy as breathing but let me just say that this is the first time I have ever attempted working with an API using <a title="Documentation on the REST protocol" href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a>, and also this is the first time attempting to build an application on the MAC, but I have had some experience building iPhone applications. So needless to say I am a beginner at this.</p>
<p>Now, for many online API&#8217;s there needs to be some kind of authorization that happens, which makes since, and the Remember The Milk REST API requires that you send a correctly formatted URL to them. One of the major parts of this url is the signature. The REST signature is a combination of several different strings tied together and hashed using MD5. It may be good to note here that MD5 is NOT encryption, and never use it as such. Its basically my understanding that all MD5 does is take a string and produce a binary code that can be decoded just about anywhere. So all in all after the signature is hashed using MD5 it should look something like this.</p>
<p>00be938d9cab78d2e24dfa21f40f4e0caf1</p>
<p>Yeah, just a bunch of gibberish. Notice that its all lowercase, more on that in a bit.</p>
<p>Ok, regardless of what its going to be used for the basic need here is to take a string(any string) turn it into an MD5 hash then return that has as a UTF-8 encoded string. The reason for the UTF-8 encoding si that most of these REST API&#8217;s call for it. Unfortunately Cocoa doesn&#8217;t seem to have any nice and simple method to produce an MD5, even after hour of searching on the net I still find this hard to believe. It would be so nice if we could just do this: md5(&#8216;mystring&#8217;) and get a nicely formatted string.</p>
<p>For my project I created a class called Utilities and placed the following method there. This is a good idea because we really want this method to be reusable for every project that we may undertake, but all we want to have to do is include these file in our project and have the functionality easily accessible.</p>
<p><strong><em>Utilities.h</em></strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;Cocoa/Cocoa.h&gt;</span>
<span style="color: #6e371a;">#import &lt;CommonCrypto/CommonDigest.h&gt;</span>
<span style="color: #a61390;">@interface</span> Utilities <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> <span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//generates md5 hash from a string</span>
<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> returnMD5Hash<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>concat;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>As you can see from above you will need to Import &lt;CommonCrypto/CommonDigest.h&gt; into your class, which provides some cryptographic voodoo which I am not bothering to learn unless absolutely necessary.  Next is the normal @interface, then the class method to produce an MD5 hash.</p>
<p><strong><em>Utilities.m</em></strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;Utilities.h&quot;</span>
<span style="color: #a61390;">@implementation</span> Utilities
&nbsp;
<span style="color: #11740a; font-style: italic;">//generate md5 hash from string</span>
<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> returnMD5Hash<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>concat <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span>concat_str <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>concat UTF8String<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">unsigned</span> <span style="color: #a61390;">char</span> result<span style="color: #002200;">&#91;</span>CC_MD5_DIGEST_LENGTH<span style="color: #002200;">&#93;</span>;
    CC_MD5<span style="color: #002200;">&#40;</span>concat_str, <span style="color: #a61390;">strlen</span><span style="color: #002200;">&#40;</span>concat_str<span style="color: #002200;">&#41;</span>, result<span style="color: #002200;">&#41;</span>;
    <span style="color: #400080;">NSMutableString</span> <span style="color: #002200;">*</span>hash <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableString</span> <span style="color: #a61390;">string</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;">16</span>; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span>
        <span style="color: #002200;">&#91;</span>hash appendFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%02X&quot;</span>, result<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>hash lowercaseString<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Above is the objective-c class method used to return a MD5 hash. All you would need to do is call the class method within any other class in your project like this.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>rtmApiSig <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>Utilities returnMD5Hash<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;%@api_key%@method%@&quot;</span>, rtmSecret, rtmApiKey, rtmMethod<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>This is the actual code that I used for my Remember The Milk signature. A more simple way to demonstrate the usage of this would be.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>myMD5String <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>Utilities returnMD5Hash<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;test&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>This will produce, <strong>098f6bcd4621d373cade4e832627b4f6</strong>. You can test your results by using <a title="Test or compare your generated md5 hash to see if its correct" href="http://www.adamek.biz/md5-generator.php">this great tool</a>.</p>
<p>One of the problems that I ran into is that most REST API&#8217;s require the hash to be lowercase and after wondering for to long of why the heck it wasn&#8217;t working I used that tool to figure out that the hash I was producing was incorrect, so I quickly changed the method to produce a lowercase string and everything was fixed.</p>
<p>So, now you should have a new utilities class which you can start piling with things like this for easy reuse in everyone of your projects. I haven&#8217;t done any extensive testing but you should be able to use this code for an iPhone application. But one thing I am sure about is that you can use this MD5 has for the Remember The Milk API or the Flickr API.</p>
<p><strong>Please let me know if you have any questions or maybe even a better way of doing this, I will try to answer quickly.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saobart.com/md5-has-in-objective-c/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>What is Model-View-Controller?</title>
		<link>http://www.saobart.com/what-is-model-view-controller/</link>
		<comments>http://www.saobart.com/what-is-model-view-controller/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 07:46:02 +0000</pubDate>
		<dc:creator>Gravityone</dc:creator>
				<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://www.saobart.com/?p=464</guid>
		<description><![CDATA[At first for me this concept was a bit hard to grasp, hopefully i can break it down to basics here. The Model-View-Controller is basically a design theory and a very logical organization of the parts or an iPhone application. Model is basically the classes that hold your application&#8217;s data. For example if you created [...]]]></description>
			<content:encoded><![CDATA[<p>At first for me this concept was a bit hard to grasp, hopefully i can break it down to basics here.</p>
<p>The Model-View-Controller is basically a design theory and a very logical organization of the parts or an iPhone application.</p>
<p><strong>Model</strong> is basically the classes that hold your application&#8217;s data. For example if you created an application that when a button was pressed would take the name of that button (a string) then output that string to a label or a text field, then in this instance the Model object would be the string itself, the actual data that was used and transferred. This is a very loose example actually but, its simplicity I think makes the Model object more understandable. Most application that use a Model object will be storing or preserving data like when using Core Data classes.<span id="more-464"></span></p>
<p><strong>View</strong> is fairly easy, if you can see it then its place in the MVC theory is <strong>View</strong>.  Although in some application there is a necessity for View objects to be hidden or invisible, these are still considered to be View objects. A view object can be windows, buttons, labels, etc&#8230;</p>
<p><strong>Controller</strong> is the mediator between the Model and View. A controller object interprets user actions made in view objects and communicates new or changed data to the model layer. When model objects change, a controller object communicates that new model data to the view objects so that they can display it. Simply, the Controller object looks at changes from either the Model or View and Tell them how to behave.</p>
<p><a href="http://saob-wp-plugin.s3.amazonaws.com/wp-content/uploads/2010/01/model_view_controller.jpg"><img class="aligncenter size-full wp-image-465" title="model_view_controller" src="http://saob-wp-plugin.s3.amazonaws.com/wp-content/uploads/2010/01/model_view_controller.jpg" alt="" width="440" height="125" /></a></p>
<p>The main reason for MVC theory is very similar to Object Oriented theory, where any object that is written should be easily identifiable as belonging to one of these three categories and no functionality within that object could be classified as belonging to any of the other two categories. Its all about abstraction and portability! An object that implements a button (View) should contain code that processes data (Controller) when it is tapped.  A class that implements a button can be used in any application but, a class that implements a button that processes a specific action or calculation can only be used in that one particular application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.saobart.com/what-is-model-view-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What are Actions?</title>
		<link>http://www.saobart.com/what-are-actions/</link>
		<comments>http://www.saobart.com/what-are-actions/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 07:01:15 +0000</pubDate>
		<dc:creator>Gravityone</dc:creator>
				<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://www.saobart.com/?p=461</guid>
		<description><![CDATA[Actions are methods that are part of your controller class and are declared with a special keyword, IBAction.  This keyword tells Interface Builder that this is an action and can be triggered by a control.  In short if you want to have interface objects in the nib (like buttons) trigger methods in the controller class [...]]]></description>
			<content:encoded><![CDATA[<p>Actions are methods that are part of your controller class and are declared with a special keyword, <strong>IBAction</strong>.  This keyword tells Interface Builder that this is an action and can be triggered by a control.  In short if you want to have interface objects in the nib (like buttons) trigger methods in the controller class then you would use special methods called Actions.<span id="more-461"></span></p>
<p>Example declaration of an action method:</p>
<p><code>- (IBAction)doSomething:(id)sender;</code></p>
<ul>
<li>-(IBAction) = the return type</li>
<li>doSomething: = name of the action</li>
<li>(id) = argument</li>
<li>sender; = argument name</li>
</ul>
<p>The name of the action can be anything you want but must have a return type of <strong>IBAction</strong>, which is the same as declaring a return type of -(void).  It just says that action methods do not return a value.</p>
<p>Usually an action method will take one argument and is typically defined as id and given a name of sender.  (id)sender; is not always necessary when declaring an action method but is typically used all the time.  The purpose of (id)sender; is to contain a reference to the control that has triggered the action method.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.saobart.com/what-are-actions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What are Outlets?</title>
		<link>http://www.saobart.com/what-are-outlets/</link>
		<comments>http://www.saobart.com/what-are-outlets/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 02:49:17 +0000</pubDate>
		<dc:creator>Gravityone</dc:creator>
				<category><![CDATA[iPhone Development]]></category>
		<category><![CDATA[basics]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.saobart.com/?p=446</guid>
		<description><![CDATA[When building an iPhone app there comes a need for the code you write to interact with the elements you create in Interface Builder, this is called an Outlet. The Outlet is and instance variable, and our controller class can refer to objects in the nib by using Outlets.  Outlets are used to effect objects [...]]]></description>
			<content:encoded><![CDATA[<p>When building an iPhone app there comes a need for the code you write to interact with the elements you create in Interface Builder, this is called an Outlet.</p>
<p>The Outlet is and instance variable, and our controller class can refer to objects in the nib by using Outlets.  Outlets are used to effect objects in your nib such as text labels, buttons and so on.  By declaring an outlet and connecting that outlet to an object in the nib, you could use the outlet from within your code to change any object in your nib.<span id="more-446"></span></p>
<p>The Outlet is declared using (IBoutlet)</p>
<p>Example:</p>
<pre>@property (nonatomic, retain) <strong>IBOutlet</strong> UILabel *statusText;</pre>
<p>The IBOutlet keyword is defined like this:</p>
<p>#ifndef IBOutlet<br />
#define IBOutlet<br />
#endif</p>
<p><strong>IBOutlet</strong> does nothing as far as the compiler is concerned. Its purpose is to act as an indicator or hint to tell Interface Builder that this is an instance variable that were going to use to connect to an object in the nib. At any time if you want an instance variable to connect to an object in the nib then it must be preceded by the <strong>IBOutlet</strong> keyword.</p>
<p>Connections made from your code to the nib must use these instance variables.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.saobart.com/what-are-outlets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
