<?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; tr.im api</title>
	<atom:link href="http://www.icodeblog.com/tag/tr-im-api/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>iPhone Coding Snippet â€“ Shortening URLs</title>
		<link>http://www.icodeblog.com/2010/02/04/iphone-coding-recipe-shortening-urls/</link>
		<comments>http://www.icodeblog.com/2010/02/04/iphone-coding-recipe-shortening-urls/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 21:42:35 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[iPhone Coding]]></category>
		<category><![CDATA[tr.im api]]></category>
		<category><![CDATA[url shortening iphone]]></category>

		<guid isPermaLink="false">http://icodeblog.com/?p=1756</guid>
		<description><![CDATA[I had some a to shorten URLs for an in-application Twitter client I'm working on and thought I would share my simple solution with you guys.

It's actually pretty straight forward and can be done in 1 line of code.  I have broken it up into several for clarity.]]></description>
			<content:encoded><![CDATA[<p>I had some a to shorten URLs for an in-application Twitter client I&#8217;m working on and thought I would share my simple solution with you guys.</p>
<p>It&#8217;s actually prettyÂ straightÂ forward and can be done in 1 line of code. Â I have broken it up into several for clarity.</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>url    <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://brandontreb.com&quot;</span>;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>apiEndpoint <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;http://api.tr.im/v1/trim_simple?url=%@&quot;</span>,url<span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>shortURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithContentsOfURL<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span>apiEndpoint<span style="color: #002200;">&#93;</span>
		 encoding<span style="color: #002200;">:</span>NSASCIIStringEncoding
		 error<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Long: %@ - Short: %@&quot;</span>,url,shortURL<span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Outputs Long: http://brandontreb.com - Short: http://tr.im/MRDd</span></pre></div></div>

<p>Pretty easy huh?</p>
<p>The magic here is in a method that Apple gave us as part of NSString.  This method is called stringWithContentsOfURL.  It will easily allow you to grab the text of any remote source.</p>
<p>I have used Tr.im as an example here because their service is very easy to use and has little overhead. Â I would have used bit.ly but they return a JSON string which would then have to be parsed. Â Tr.im&#8217;s trim_simple service simply outputs the string of the shortened URL.</p>
<p>Sure Twitter may shorten links for you automatically, but what if you want to use a custom service? Or,&#8230;wait for it&#8230; use it for something other than Twitter (please post in the comments if you do. I would love to hear some other uses <img src='http://www.icodeblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</p>
<p>Questions? Comments? Complaints?</p>
<p>Happy iCoding</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icodeblog.com/2010/02/04/iphone-coding-recipe-shortening-urls/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
	</channel>
</rss>

