<?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>farp.blog &#187; objc</title>
	<atom:link href="http://fredandrandall.com/blog/tag/objc/feed/" rel="self" type="application/rss+xml" />
	<link>http://fredandrandall.com/blog</link>
	<description>Bloggin&#039; about whatever</description>
	<lastBuildDate>Tue, 04 Nov 2014 07:15:30 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.38</generator>
	<item>
		<title>Building a static library that works on the iPhone and the simulator</title>
		<link>http://fredandrandall.com/blog/2011/10/22/building-a-static-library-that-works-on-the-iphone-and-the-simulator/</link>
		<comments>http://fredandrandall.com/blog/2011/10/22/building-a-static-library-that-works-on-the-iphone-and-the-simulator/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 15:03:15 +0000</pubDate>
		<dc:creator><![CDATA[Randall]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[objc]]></category>

		<guid isPermaLink="false">http://fredandrandall.com/blog/?p=629</guid>
		<description><![CDATA[Apple&#8217;s iPhone simulator runs really smooth and fast. This is because they aren&#8217;t emulating the ARM code on your Mac, they&#8217;re actually building x86 binaries that will run in the simulator. Because of this, code written for the iPhone needs &#8230; <a href="http://fredandrandall.com/blog/2011/10/22/building-a-static-library-that-works-on-the-iphone-and-the-simulator/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Apple&#8217;s iPhone simulator runs really smooth and fast. This is because they aren&#8217;t emulating the ARM code on your Mac, they&#8217;re actually building x86 binaries that will run in the simulator.</p>
<p>Because of this, code written for the iPhone needs to be compiled twice, once for the simulator and once for the device. This makes working with static libraries a bit of a pain, because you need two of them, one for each architecture.</p>
<p>Luckily, it&#8217;s possible to build a &#8220;universal&#8221; binary that will work with both architectures. Apple did this during their switch from PowerPC to Intel.<br />
<span id="more-629"></span></p>
<p>I found the directions in <a href="http://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4">this StackOverflow post</a>.</p>
<p><a href="http://fredandrandall.com/blog/wp-content/uploads/2011/10/buildPhase.png"><img class="aligncenter size-full wp-image-633" title="buildPhase" src="http://fredandrandall.com/blog/wp-content/uploads/2011/10/buildPhase.png" alt="" width="877" height="443" /></a></p>
<ul>
<li>All you need to do is create a new static library target.</li>
<li>Add a &#8220;Run Script&#8221; build phase.</li>
<li>Copy and paste this script in.</li>
<li>Your build output should be in a folder labeled Debug_universal or Release_universal</li>
</ul>
<pre class="brush: bash; title: ; notranslate">
# Version 2.0 (updated for Xcode 4, with some fixes)
# Changes:
#    - Works with xcode 4, even when running xcode 3 projects (Workarounds for apple bugs)
#    - Faster / better: only runs lipo once, instead of once per recursion
#    - Added some debugging statemetns that can be switched on/off by changing the DEBUG_THIS_SCRIPT variable to &quot;true&quot;
#    - Fixed some typos
#
# Purpose:
#   Create a static library for iPhone from within XCode
#   Because Apple staff DELIBERATELY broke Xcode to make this impossible from the GUI (Xcode 3.2.3 specifically states this in the Release notes!)
#   ...no, I don't understand why they did this!
#
# Author: Adam Martin - http://twitter.com/redglassesapps
# Based on: original script from Eonil (main changes: Eonil's script WILL NOT WORK in Xcode GUI - it WILL CRASH YOUR COMPUTER)
#
# More info: see this Stack Overflow question: http://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4

#################[ Tests: helps workaround any future bugs in Xcode ]########
#
DEBUG_THIS_SCRIPT=&quot;false&quot;

if [ $DEBUG_THIS_SCRIPT = &quot;true&quot; ]
then
echo &quot;########### TESTS #############&quot;
echo &quot;Use the following variables when debugging this script; note that they may change on recursions&quot;
echo &quot;BUILD_DIR = $BUILD_DIR&quot;
echo &quot;BUILD_ROOT = $BUILD_ROOT&quot;
echo &quot;CONFIGURATION_BUILD_DIR = $CONFIGURATION_BUILD_DIR&quot;
echo &quot;BUILT_PRODUCTS_DIR = $BUILT_PRODUCTS_DIR&quot;
echo &quot;CONFIGURATION_TEMP_DIR = $CONFIGURATION_TEMP_DIR&quot;
echo &quot;TARGET_BUILD_DIR = $TARGET_BUILD_DIR&quot;
fi

#####################[ part 1 ]##################
# First, work out the BASESDK version number (NB: Apple ought to report this, but they hide it)
#    (incidental: searching for substrings in sh is a nightmare! Sob)

SDK_VERSION=$(echo ${SDK_NAME} | grep -o '.\{3\}$')

# Next, work out if we're in SIM or DEVICE

if [ ${PLATFORM_NAME} = &quot;iphonesimulator&quot; ]
then
OTHER_SDK_TO_BUILD=iphoneos${SDK_VERSION}
else
OTHER_SDK_TO_BUILD=iphonesimulator${SDK_VERSION}
fi

echo &quot;XCode has selected SDK: ${PLATFORM_NAME} with version: ${SDK_VERSION} (although back-targetting: ${IPHONEOS_DEPLOYMENT_TARGET})&quot;
echo &quot;...therefore, OTHER_SDK_TO_BUILD = ${OTHER_SDK_TO_BUILD}&quot;
#
#####################[ end of part 1 ]##################

#####################[ part 2 ]##################
#
# IF this is the original invocation, invoke WHATEVER other builds are required
#
# Xcode is already building ONE target...
#
# ...but this is a LIBRARY, so Apple is wrong to set it to build just one.
# ...we need to build ALL targets
# ...we MUST NOT re-build the target that is ALREADY being built: Xcode WILL CRASH YOUR COMPUTER if you try this (infinite recursion!)
#
#
# So: build ONLY the missing platforms/configurations.

if [ &quot;true&quot; == ${ALREADYINVOKED:-false} ]
then
echo &quot;RECURSION: I am NOT the root invocation, so I'm NOT going to recurse&quot;
else
# CRITICAL:
# Prevent infinite recursion (Xcode sucks)
export ALREADYINVOKED=&quot;true&quot;

echo &quot;RECURSION: I am the root ... recursing all missing build targets NOW...&quot;
echo &quot;RECURSION: ...about to invoke: xcodebuild -configuration \&quot;${CONFIGURATION}\&quot; -target \&quot;${TARGET_NAME}\&quot; -sdk \&quot;${OTHER_SDK_TO_BUILD}\&quot; ${ACTION} RUN_CLANG_STATIC_ANALYZER=NO&quot;
xcodebuild -configuration &quot;${CONFIGURATION}&quot; -target &quot;${TARGET_NAME}&quot; -sdk &quot;${OTHER_SDK_TO_BUILD}&quot; ${ACTION} RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR=&quot;${BUILD_DIR}&quot; BUILD_ROOT=&quot;${BUILD_ROOT}&quot;

ACTION=&quot;build&quot;

#Merge all platform binaries as a fat binary for each configurations.

# Calculate where the (multiple) built files are coming from:
CURRENTCONFIG_DEVICE_DIR=${SYMROOT}/${CONFIGURATION}-iphoneos
CURRENTCONFIG_SIMULATOR_DIR=${SYMROOT}/${CONFIGURATION}-iphonesimulator

echo &quot;Taking device build from: ${CURRENTCONFIG_DEVICE_DIR}&quot;
echo &quot;Taking simulator build from: ${CURRENTCONFIG_SIMULATOR_DIR}&quot;

CREATING_UNIVERSAL_DIR=${SYMROOT}/${CONFIGURATION}-universal
echo &quot;...I will output a universal build to: ${CREATING_UNIVERSAL_DIR}&quot;

# ... remove the products of previous runs of this script
#      NB: this directory is ONLY created by this script - it should be safe to delete!

rm -rf &quot;${CREATING_UNIVERSAL_DIR}&quot;
mkdir &quot;${CREATING_UNIVERSAL_DIR}&quot;

#
echo &quot;lipo: for current configuration (${CONFIGURATION}) creating output file: ${CREATING_UNIVERSAL_DIR}/${EXECUTABLE_NAME}&quot;
lipo -create -output &quot;${CREATING_UNIVERSAL_DIR}/${EXECUTABLE_NAME}&quot; &quot;${CURRENTCONFIG_DEVICE_DIR}/${EXECUTABLE_NAME}&quot; &quot;${CURRENTCONFIG_SIMULATOR_DIR}/${EXECUTABLE_NAME}&quot;

#########
#
# Added: StackOverflow suggestion to also copy &quot;include&quot; files
#    (untested, but should work OK)
#
if [ -d &quot;${CURRENTCONFIG_DEVICE_DIR}/usr/local/include&quot; ]
then
mkdir -p &quot;${CREATING_UNIVERSAL_DIR}/usr/local/include&quot;
# * needs to be outside the double quotes?
cp &quot;${CURRENTCONFIG_DEVICE_DIR}/usr/local/include/&quot;* &quot;${CREATING_UNIVERSAL_DIR}/usr/local/include&quot;
fi
fi
</pre>
]]></content:encoded>
			<wfw:commentRss>http://fredandrandall.com/blog/2011/10/22/building-a-static-library-that-works-on-the-iphone-and-the-simulator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to change the color of UIBarButtonItem on iOS 5</title>
		<link>http://fredandrandall.com/blog/2011/10/15/how-to-change-the-color-of-uibarbuttonitem-on-ios-5/</link>
		<comments>http://fredandrandall.com/blog/2011/10/15/how-to-change-the-color-of-uibarbuttonitem-on-ios-5/#comments</comments>
		<pubDate>Sat, 15 Oct 2011 19:45:26 +0000</pubDate>
		<dc:creator><![CDATA[Randall]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[iOS 5]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[objc]]></category>

		<guid isPermaLink="false">http://fredandrandall.com/blog/?p=623</guid>
		<description><![CDATA[My most popular blog post is how to change the color of a UIBarButtonItem. It&#8217;s something that lots of people want to do, but it involved some pretty weird hacks to get it working. Now that iOS 5 is out, &#8230; <a href="http://fredandrandall.com/blog/2011/10/15/how-to-change-the-color-of-uibarbuttonitem-on-ios-5/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>My <a href="http://fredandrandall.com/blog/2011/03/31/how-to-change-the-color-of-a-uibarbuttonitem/" title="How to change the color of a UIBarButtonItem">most popular blog post</a> is how to change the color of a UIBarButtonItem. It&#8217;s something that lots of people want to do, but it involved some pretty weird hacks to get it working.</p>
<p>Now that iOS 5 is out, I can talk about a better way to do it. Apple will now let you set the <code>tintColor:</code> property on the bar button item. That&#8217;s it. No more weird hacks with images or segmented controls.</p>
<p>There&#8217;s even a cool new appearance proxy that will let you change all controls from your app with a single line of code. (More about UIAppearance <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAppearance_Protocol/Reference/Reference.html">here</a>)</p>
<p>So lets say you want every UIBarButtonItem in your application to be blue. That&#8217;s easy just call <code>[UIBarButtonItem appearance] setTintColor:[UIColor blueColor]]</code></p>
<p>Remember, this is iOS 5 only. If you want your app to support iOS 4, you&#8217;ll have to do it <a href="http://fredandrandall.com/blog/2011/03/31/how-to-change-the-color-of-a-uibarbuttonitem/" title="How to change the color of a UIBarButtonItem">the old way</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://fredandrandall.com/blog/2011/10/15/how-to-change-the-color-of-uibarbuttonitem-on-ios-5/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to make your app open in full screen on Lion</title>
		<link>http://fredandrandall.com/blog/2011/09/08/how-to-make-your-app-open-in-full-screen-on-lion/</link>
		<comments>http://fredandrandall.com/blog/2011/09/08/how-to-make-your-app-open-in-full-screen-on-lion/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 02:37:03 +0000</pubDate>
		<dc:creator><![CDATA[Randall]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[fullscreen]]></category>
		<category><![CDATA[lion]]></category>
		<category><![CDATA[objc]]></category>

		<guid isPermaLink="false">http://fredandrandall.com/blog/?p=540</guid>
		<description><![CDATA[One of Lions new features is full screen apps. Full screening an app is supposed to remove all distractions and make room for more of the app&#8217;s UI. Actually implementing this in your app is quite simple, but finding how &#8230; <a href="http://fredandrandall.com/blog/2011/09/08/how-to-make-your-app-open-in-full-screen-on-lion/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://fredandrandall.com/blog/wp-content/uploads/2011/09/Screen-Shot-2011-09-08-at-10.21.08-PM.png"><img class="alignleft size-full wp-image-543" title="Screen Shot 2011-09-08 at 10.21.08 PM" src="http://fredandrandall.com/blog/wp-content/uploads/2011/09/Screen-Shot-2011-09-08-at-10.21.08-PM.png" alt="" width="77" height="75" /></a>One of Lions new features is full screen apps. Full screening an app is supposed to remove all distractions and make room for more of the app&#8217;s UI. Actually implementing this in your app is quite simple, but finding how to do it online can be a bit tricky.</p>
<p>There are two ways to do it, one is with NSApplication and the other is with NSWindow.</p>
<p>To do it with NSApplication, you&#8217;ll make this simple call</p>
<pre class="brush: objc; title: ; notranslate">
   [[NSApplication sharedApplication]
           setPresentationOptions:NSFullScreenWindowMask];
</pre>
<p>To do it with NSWindow you&#8217;ll make this one</p>
<pre class="brush: objc; title: ; notranslate">
   [window setCollectionBehavior:
             NSWindowCollectionBehaviorFullScreenPrimary];
</pre>
<p>There is also an <code>NSWindowCollectionBehaviorFullScreenAuxiliary</code> that you can use to allow auxiliary windows to show up in the space with the main window.</p>
<p>Calling either of these methods will add the resize button to the upper right corner of the window. You can call them at any time also. If you want it to be in the app all the time, call it somewhere like <code>applicationDidFinishLaunching</code>.</p>
<p>One thing to remember is that fullscreen functionality like this is LION ONLY. If you&#8217;re using this in an app that targets more than 10.7, make sure to do the appropriate checks around this code.</p>
]]></content:encoded>
			<wfw:commentRss>http://fredandrandall.com/blog/2011/09/08/how-to-make-your-app-open-in-full-screen-on-lion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Automatic Link Detection in an NSTextView</title>
		<link>http://fredandrandall.com/blog/2011/08/16/automatic-link-detection-in-an-nstextview/</link>
		<comments>http://fredandrandall.com/blog/2011/08/16/automatic-link-detection-in-an-nstextview/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 03:48:19 +0000</pubDate>
		<dc:creator><![CDATA[Randall]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[NSTextView]]></category>
		<category><![CDATA[objc]]></category>

		<guid isPermaLink="false">http://fredandrandall.com/blog/?p=506</guid>
		<description><![CDATA[NSTextView is a really powerful text view class. It can do all kinds of stuff like automatic spelling correction, email, phone number, and address detection, and link detection. I was working on a chat application and I wanted to have &#8230; <a href="http://fredandrandall.com/blog/2011/08/16/automatic-link-detection-in-an-nstextview/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>NSTextView is a really powerful text view class. It can do all kinds of stuff like automatic spelling correction, email, phone number, and address detection, and link detection. I was working on a chat application and I wanted to have links that people sent be clickable. I was using an NSTextView because it has the automaticLinkDetection property.</p>
<p>Unfortunately, I couldn&#8217;t get links to show up in my app. I tried sending it delegate messages and lots of other stuff. It just wouldn&#8217;t work when I set the text programatically. It would only work when I was actually typing in to the NSTextView and even then, it was a little flaky. I posted a <a href="http://stackoverflow.com/questions/7055131/automatic-link-detection-not-working-in-nstextview-after-programmatically-setting">question on StackOverflow</a> and didn&#8217;t get any answers.</p>
<p>So to fix the problem, I did the link detection myself. I look through the text view for links and then add them myself as NSAttributedStrings. I did this using three different categories.</p>
<p>There is <a href="http://snippets.aktagon.com/snippets/358-How-to-make-a-clickable-link-inside-a-NSTextField-and-Cocoa">NSAttributedString+Hyperlink</a>, NSString+FindURLs, and NSTextView+AutomaticLinkDetection. I use the FindURLs category to find the links and their locations, then I use the Hyperlink category to format the string like a link, and the AutomaticLinkDetection category to bring them together.</p>
<p>You use it like this</p>
<pre class="brush: objc; title: ; notranslate">
   [myTextView setString:@&quot;http://google.com http://apple.com&quot;];
   [myTextView detectAndAddLinks];
</pre>
<p>And here is the implementation</p>
<pre class="brush: objc; title: ; notranslate">
-(void)detectAndAddLinks
{
   NSArray *linkLocations = [[self string] locationsOfLinks];
   NSArray *links = [[self string] arrayOfLinks];

   int i=0;
   for( NSString *link in links )
   {
      NSAttributedString *linkString = [NSAttributedString hyperlinkFromString:link withURL:[NSURL URLWithString:link]];
      [[self textStorage] replaceCharactersInRange:[[linkLocations objectAtIndex:i] range] withAttributedString:linkString];
      i++;
   }

}
</pre>
<p>I put an <a href="https://github.com/blladnar/AutoLink">example project on GitHub</a> that you can look at and use.</p>
<p>Let me know if there was something I missed that would make it so I don&#8217;t have to use the category.</p>
]]></content:encoded>
			<wfw:commentRss>http://fredandrandall.com/blog/2011/08/16/automatic-link-detection-in-an-nstextview/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to launch your Mac/iOS app with a custom URL</title>
		<link>http://fredandrandall.com/blog/2011/07/30/how-to-launch-your-macios-app-with-a-custom-url/</link>
		<comments>http://fredandrandall.com/blog/2011/07/30/how-to-launch-your-macios-app-with-a-custom-url/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 23:02:09 +0000</pubDate>
		<dc:creator><![CDATA[Randall]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[custom url]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[MacOS]]></category>
		<category><![CDATA[objc]]></category>

		<guid isPermaLink="false">http://fredandrandall.com/blog/?p=473</guid>
		<description><![CDATA[One interesting feature of iOS and Mac apps is the ability for them to be launched by a custom URL. What this means is that you can set up your app to respond to different links in different ways. Clicking &#8230; <a href="http://fredandrandall.com/blog/2011/07/30/how-to-launch-your-macios-app-with-a-custom-url/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://fredandrandall.com/blog/wp-content/uploads/2011/07/http.jpg"><img class="alignleft size-medium wp-image-488" title="http" src="http://fredandrandall.com/blog/wp-content/uploads/2011/07/http-300x197.jpg" alt="" width="210" height="138" /></a>One interesting feature of iOS and Mac apps is the ability for them to be launched by a custom URL. What this means is that you can set up your app to respond to different links in different ways.</p>
<p>Clicking a link that says myTwitterApp://sendTweet?tweet=hello could send a tweet from your twitter app. It could also be used for configuring your app. Maybe you have an email app that needs some special server configurations. It could be set up so that you just have to visit a webpage on your server and click a link and have it automatically configure your email settings.</p>
<p>Facebook uses the URL scheme for authentication in their iPhone app. If I have an app that wants to authenticate with Facebook, it will try and talk to the Facebook app on the phone so I don&#8217;t have to authenticate again in my other app.</p>
<p>I think this is a pretty underused feature and I would bet there are TONS of clever things people can do with it. So how do you actually do it?<span id="more-473"></span></p>
<p>I&#8217;m going to show you how I&#8217;m adding it to the next versions of Thoughtback.</p>
<p>Your first step is adding a URL type to your app&#8217;s info.plist. You will add the same key if you&#8217;re making an iOS or Mac app. The raw key is CFBundleURLTypes.</p>
<p><a href="http://fredandrandall.com/blog/wp-content/uploads/2011/07/urltype.png"><img class="aligncenter size-medium wp-image-474" title="urltype" src="http://fredandrandall.com/blog/wp-content/uploads/2011/07/urltype-300x66.png" alt="" width="300" height="66" /></a></p>
<p>Once the key is added links that start with thoughtback:// will launch the apps on both iOS and OS X.</p>
<p>Just launching from a URL is fine, but how do you get any information out of the URL that was clicked? That&#8217;s where the process differs between the two platforms.</p>
<p><strong>iOS</strong><br />
Go into your applicationdelegate and override either of these two methods.</p>
<pre>- (BOOL)application:(UIApplication *)application 
           handleOpenURL:(NSURL *)url

- (BOOL)application:(UIApplication *)application 
            openURL:(NSURL *)url 
  sourceApplication:(NSString*)sourceApplication 
         annotation:(id)annotation</pre>
<p><em></em>I should mention that the first method is deprecated, but the second one is only available on iOS 4.2 or later.</p>
<p><strong>Mac OS</strong><br />
This is slightly different on the mac, URL handling is not part of the NSApplicationDelegate protocol.</p>
<p>What you&#8217;ll need to do is tell the application to respond to an Apple Event.</p>
<pre class="brush: objc; title: ; notranslate">
-(void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
    NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
    [appleEventManager setEventHandler:self
                           andSelector:@selector(handleGetURLEvent:withReplyEvent:)
                         forEventClass:kInternetEventClass andEventID:kAEGetURL];
}

- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
    NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
}
</pre>
<p><strong>Parsing the URL</strong><br />
So now that you have the URL that launched your app, you&#8217;ll want to get the information out of the string. The most typical way to send information is with a query string. Here&#8217;s an example that Thoughtback will use.</p>
<p>thoughtback://send?thought=Interesting Thought&amp;redirect=http://fredandrandall.com</p>
<p>We want to pull out a few different things from that. First we want to grab &#8220;send&#8221; because that&#8217;s the action thoughtback will take. Then we want to get the thought that will be sent and the url that Thoughtback will redirect to when it&#8217;s done sending the thought.</p>
<p>To parse out &#8220;send&#8221; we can use NSURL&#8217;s host method.</p>
<p>To get the query string, we can use NSURL&#8217;s query method.</p>
<p>Parsing the query string is a little more difficult but this block of code, that I found on <a href="http://stackoverflow.com/questions/6591280/how-to-parse-an-asset-url-in-objective-c">StackOverflow</a>, will put it into an NSDictionary for you.</p>
<pre class="brush: objc; title: ; notranslate">
NSString *query = [url query];
NSArray *queryPairs = [query componentsSeparatedByString:@&quot;&amp;&quot;];
NSMutableDictionary *pairs = [NSMutableDictionary dictionary];
for (NSString *queryPair in queryPairs) {
  NSArray *bits = [queryPair componentsSeparatedByString:@&quot;=&quot;];
  if ([bits count] != 2) { continue; }

  NSString *key = [[bits objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  NSString *value = [[bits objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

  [pairs setObject:value forKey:key];
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://fredandrandall.com/blog/2011/07/30/how-to-launch-your-macios-app-with-a-custom-url/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to change the color of a UIBarButtonItem</title>
		<link>http://fredandrandall.com/blog/2011/03/31/how-to-change-the-color-of-a-uibarbuttonitem/</link>
		<comments>http://fredandrandall.com/blog/2011/03/31/how-to-change-the-color-of-a-uibarbuttonitem/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 23:12:08 +0000</pubDate>
		<dc:creator><![CDATA[Randall]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[UIBarButtonItem]]></category>
		<category><![CDATA[UISegmentedControl]]></category>

		<guid isPermaLink="false">http://fredandrandall.com/blog/?p=310</guid>
		<description><![CDATA[EDIT: There is a new way to do this in iOS 5 that is much easier and nicer. If you want to support iOS 4, keep reading. A UIBarButtonItem is an item that goes on a UIToolbar or a UINavigationBar. &#8230; <a href="http://fredandrandall.com/blog/2011/03/31/how-to-change-the-color-of-a-uibarbuttonitem/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://fredandrandall.com/blog/wp-content/uploads/2011/03/UIBarButtonItemTint.png"><img class="alignleft size-medium wp-image-316" title="UIBarButtonItemTint" src="http://fredandrandall.com/blog/wp-content/uploads/2011/03/UIBarButtonItemTint-154x300.png" alt="" width="154" height="300" /></a></p>
<p><strong>EDIT: There is a <a title="How to change the color of UIBarButtonItem on iOS 5" href="http://fredandrandall.com/blog/2011/10/15/how-to-change-the-color-of-uibarbuttonitem-on-ios-5/">new way to do this</a> in iOS 5 that is much easier and nicer. If you want to support iOS 4, keep reading.</strong></p>
<p>A UIBarButtonItem is an item that goes on a UIToolbar or a UINavigationBar. It&#8217;s typically a button but it can be a bunch of different things. I&#8217;m going to talk about the button. A UIBarButtonItem button takes on the color of the bar that it is on. You can set the tint of a UIToolbar, but you can&#8217;t change the colors of the buttons on it.</p>
<p>I found lots of different solutions for this online, most involving adding a UIButton as the customView of the UIBarButtonItem and having some sort of image for the color you need. That works fine, until you need a color that you don&#8217;t have an image for.</p>
<p>I found a better solution <a href="http://charles.lescampeurs.org/2011/02/10/tint-color-uibutton-and-uibarbuttonitem">here</a>. Basically what they figured out was that a UISegmentedControl with a style of UISegmentedControlStyleBar looks just like a UIBarButtonItem. A key difference is that UISegmentedControl has a nice <a href="http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UISegmentedControl_Class/Reference/UISegmentedControl.html#//apple_ref/occ/instp/UISegmentedControl/tintColor">tintColor</a> property that you can use to change the colors.</p>
<p>So what I did was take <a href="https://github.com/CharlyBr/MrBrown-Blob">CharlyBr</a>&#8216;s code and put it into a UIBarButtonItem category.</p>
<pre class="brush: objc; title: ; notranslate">
+(UIBarButtonItem*)barButtonItemWithTint:(UIColor*)color andTitle:(NSString*)itemTitle andTarget:(id)theTarget andSelector:(SEL)selector
{
	UISegmentedControl *button = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:itemTitle, nil]] autorelease];
	button.momentary = YES;
	button.segmentedControlStyle = UISegmentedControlStyleBar;
	button.tintColor = color;
	[button addTarget:theTarget action:selector forControlEvents:UIControlEventValueChanged];

	UIBarButtonItem *removeButton = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];

	return removeButton;
}
</pre>
<p>You can check out my example project on <a href="https://github.com/blladnar/UIBarButtonItem-Tint">GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://fredandrandall.com/blog/2011/03/31/how-to-change-the-color-of-a-uibarbuttonitem/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Simple imgur iPhone Uploader</title>
		<link>http://fredandrandall.com/blog/2011/02/26/simple-imgur-iphone-uploader/</link>
		<comments>http://fredandrandall.com/blog/2011/02/26/simple-imgur-iphone-uploader/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 23:01:27 +0000</pubDate>
		<dc:creator><![CDATA[Randall]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[imgur]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[uploader]]></category>

		<guid isPermaLink="false">http://fredandrandall.com/blog/?p=259</guid>
		<description><![CDATA[Recently I&#8217;ve been toying with the idea of adding image uploading to Thoughtback. One easy way to do that is to use another image host and just post a link in the thought. I decided to try out imgur because &#8230; <a href="http://fredandrandall.com/blog/2011/02/26/simple-imgur-iphone-uploader/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://fredandrandall.com/blog/wp-content/uploads/2011/02/imgurimage.png"><img class="alignleft size-full wp-image-275" title="imgurimage" src="http://fredandrandall.com/blog/wp-content/uploads/2011/02/imgurimage.png" alt="" width="333" height="134" /></a>Recently I&#8217;ve been toying with the idea of adding image uploading to <a href="http://www.thoughtback.com">Thoughtback</a>. One easy way to do that is to use another image host and just post a link in the thought. I decided to try out <a href="http://www.imgur.com">imgur</a> because of their <a href="http://api.imgur.com/resources_anon">Anonymous API</a>. What it lets you do is upload images to their service, without requiring a username and password. This is great if you just want quick and easy image sharing.</p>
<p>To get started imgur has some good <a href="http://api.imgur.com/examples">examples</a> of how to upload in a variety of programming languages. I grabbed the iPhone example and copy and pasted it in thinking, &#8220;Well that was easy&#8221;. It turns out there was a little bit more to do.</p>
<p><span id="more-259"></span>Here is the iOS example from their website (with a few typos corrected)</p>
<pre class="brush: objc; title: ; notranslate">
-(NSData *)uploadPhoto:(UIImage *) image {
       NSData   *imageData  = UIImageJPEGRepresentation(image,1);
       NSString *imageB64   = [self escapeString:[imageData base64Encoding]];  //Custom implementations, no built in base64 or HTTP escaping for iPhone
       NSString *uploadCall = [NSStringstringWithFormat:@&quot;key=%@ℑ=%@&quot;,imgurKey,imageB64];

       NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@&quot;http://api.imgur.com/2/upload&quot;]];
       [request setHTTPMethod:@&quot;POST&quot;];
       [request setValue:[NSString stringWithFormat:@&quot;%d&quot;,[uploadCalllength]] forHTTPHeaderField:@&quot;Content-length&quot;];
       [request setHTTPBody:[uploadCall dataUsingEncoding:NSUTF8StringEncoding]];

       NSURLResponse *response;
       NSError *error = nil;

       NSData *XMLResponse= [NSURLConnection sendSynchronousRequest:requestreturningResponse:&amp;response error:&amp;error];

       return XMLResponse;
}
</pre>
<p>The problem with their example was that it wasn&#8217;t quite finished.<br />
<a href="http://fredandrandall.com/blog/wp-content/uploads/2011/02/apiProblem1.png"><img class="aligncenter size-full wp-image-267" title="apiProblem" src="http://fredandrandall.com/blog/wp-content/uploads/2011/02/apiProblem1.png" alt="" width="614" height="60" /></a>That <code>Database64Encoding</code> method is not a part of the iOS sdk. You need to do that yourself. So what does it mean exactly?</p>
<p>It means that you need to convert the image data to <a href="http://en.wikipedia.org/wiki/Base64">Base64</a>. That basically means turning your image data into a string so it can be sent up via a POST request. So I did a little bit of Googling and found some code that converts NSData to a Base64 NSString. I got the code from the <a href="http://mattgemmell.com/2008/02/22/mgtwitterengine-twitter-from-cocoa">MGTwitterEngine</a>, but it can be found in a few places.</p>
<p>So after that I thought I should be done. I ran the code and got an error back from imgur. Then I noticed the weird ℑ character in the request. I&#8217;m not sure what it&#8217;s for, but it didn&#8217;t work. I replaced it with &#8220;image&#8221; and I got a success back from imgur.</p>
<p>Hooray, everything seemed like it was working, but it still wasn&#8217;t. When I went to the URL in the response, there was no image. Nothing loaded. What was wrong?</p>
<p>I had a suspicion that there was some funny stuff going on with the encoding so I wrote the base64 encoded string out to a file (it was waaaay too long for NSLog to handle) to see what was actually in it. There were a bunch of /&#8217;s and +&#8217;s. These are valid URL characters that can definitely mess up query string parsing if you want them to be in one of your arguments.</p>
<p>I pulled out an NSString category I had written to escape valid URL characters and called my <code>stringByEscapingValidURLCharacters</code> method on the base64 string. After trying again I was getting valid stuff back and my image URLs were loading correctly.</p>
<p>So, to prevent others from going through the headaches to make a simple imgur uploader, I decided to open source some example code code.</p>
<p>This code is very simplistic. It is a simple iPhone app that lets you choose an image from the camera or your phone&#8217;s library and send it to imgur. The ImgurUploader class calls out to imgur and returns the URL of the original sized image by calling a delegate method. It doesn&#8217;t handle any errors right now either. You will also need to get an <a href="http://imgur.com/register/api/">API key</a> from imgur, which only takes a second. This comes with the &#8220;works on my machine&#8221; <a href="http://www.codinghorror.com/blog/2007/03/the-works-on-my-machine-certification-program.html">seal</a> of approval.</p>
<p><a href="https://github.com/blladnar/iPhone-Imgur-Uploader">Check it out on GitHub</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fredandrandall.com/blog/2011/02/26/simple-imgur-iphone-uploader/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to create a custom cocoa framework</title>
		<link>http://fredandrandall.com/blog/2011/02/04/how-to-create-a-custom-cocoa-framework/</link>
		<comments>http://fredandrandall.com/blog/2011/02/04/how-to-create-a-custom-cocoa-framework/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 04:29:53 +0000</pubDate>
		<dc:creator><![CDATA[Randall]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[thoughtback]]></category>

		<guid isPermaLink="false">http://fredandrandall.com/blog/?p=238</guid>
		<description><![CDATA[I was recently trying to rip out some code from the Thoughtback app into it&#8217;s own framework so that I could eventually open source when we decide to make our API public. I&#8217;ve used frameworks plenty of times, but I&#8217;ve never &#8230; <a href="http://fredandrandall.com/blog/2011/02/04/how-to-create-a-custom-cocoa-framework/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I was recently trying to rip out some code from the <a href="http://www.thoughtback.com">Thoughtback</a> app into it&#8217;s own framework so that I could eventually open source when we decide to make our API public. I&#8217;ve used frameworks plenty of times, but I&#8217;ve never actually made my own.</p>
<p>I started off by just using the default Cocoa Framework project that XCode makes for you. It all seemed to work just fine, but when I tried actually using the framework in a different project, it wouldn&#8217;t load. I kept getting this error</p>
<pre class="brush: plain; title: ; notranslate">Library not loaded: path/to/framework
 Referenced from: path/to/app/
 Reason: image not found</pre>
<p><span id="more-238"></span>After lots of looking around I finally figured out the problem. Frameworks can be referenced at the System level (requires admin rights to install), the User level (could be useful to share a framework between apps), and at the application level. Bundling your framework inside the application is the most common way to do that. The &#8220;image not found&#8221; error has to do with some pathing in the framework. To fix it, you&#8217;ll need to change the &#8220;Installation Directory&#8221; in the build settings of your framework. Right click on your framework&#8217;s target to bring up the info panel. Search for &#8220;Installation Directory&#8221; and set it to be <strong>@executable_path/../Frameworks</strong>.</p>
<p><a href="http://fredandrandall.com/blog/wp-content/uploads/2011/02/InstallationDirectory.png"><img class="aligncenter size-full wp-image-248" title="InstallationDirectory" src="http://fredandrandall.com/blog/wp-content/uploads/2011/02/InstallationDirectory.png" alt="" width="516" height="593" /></a></p>
<p>Now the framework should load just fine in any project you want to use it in. I still had a problem though. If you&#8217;re familiar with cocoa frameworks, you&#8217;ll know its just a bundle with a library and some header files in a certain directory structure. I looked at my framework and couldn&#8217;t find the &#8220;Headers&#8221; folder with my header files so I couldn&#8217;t use anything that was in my framework. I googled around for a little while and found nothing. Thats when I noticed the &#8220;Role&#8221; column when I clicked on my framework target. That let me set the header files to public, private, or project, depending on how I wanted them to show up in my framework.</p>
<p><a href="http://fredandrandall.com/blog/wp-content/uploads/2011/02/PublicHeader.png"><img class="aligncenter size-full wp-image-247" title="PublicHeader" src="http://fredandrandall.com/blog/wp-content/uploads/2011/02/PublicHeader.png" alt="" width="370" height="401" /></a></p>
<p>So now that I have the library path right and the header files right, there is just one thing I needed to do to get it working in my test app. You&#8217;ll need to add another build step to your application target that copies the framework to your application bundle.</p>
<ol>
<li>Right click on your application target.</li>
<li>Click &#8220;New Build Phase&#8221;</li>
<li>Click &#8220;New Copy Files Build Phase&#8221;</li>
<li>Change the destination to &#8220;Frameworks&#8221;</li>
<li>Close the window.</li>
<li>Drag and drop your framework into the build phase.</li>
</ol>
<p><object id="scPlayer" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="763" height="429" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="data" value="http://content.screencast.com/users/lladnar/folders/Jing/media/33d932c2-955a-4b9b-841e-236f5ce936e8/jingswfplayer.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#FFFFFF" /><param name="flashVars" value="thumb=http://content.screencast.com/users/lladnar/folders/Jing/media/33d932c2-955a-4b9b-841e-236f5ce936e8/FirstFrame.jpg&amp;containerwidth=763&amp;containerheight=429&amp;content=http://content.screencast.com/users/lladnar/folders/Jing/media/33d932c2-955a-4b9b-841e-236f5ce936e8/00000074.swf&amp;blurover=false" /><param name="allowFullScreen" value="true" /><param name="scale" value="showall" /><param name="allowScriptAccess" value="always" /><param name="base" value="http://content.screencast.com/users/lladnar/folders/Jing/media/33d932c2-955a-4b9b-841e-236f5ce936e8/" /><param name="src" value="http://content.screencast.com/users/lladnar/folders/Jing/media/33d932c2-955a-4b9b-841e-236f5ce936e8/jingswfplayer.swf" /><param name="flashvars" value="thumb=http://content.screencast.com/users/lladnar/folders/Jing/media/33d932c2-955a-4b9b-841e-236f5ce936e8/FirstFrame.jpg&amp;containerwidth=763&amp;containerheight=429&amp;content=http://content.screencast.com/users/lladnar/folders/Jing/media/33d932c2-955a-4b9b-841e-236f5ce936e8/00000074.swf&amp;blurover=false" /><param name="allowfullscreen" value="true" /><embed id="scPlayer" type="application/x-shockwave-flash" width="763" height="429" src="http://content.screencast.com/users/lladnar/folders/Jing/media/33d932c2-955a-4b9b-841e-236f5ce936e8/jingswfplayer.swf" base="http://content.screencast.com/users/lladnar/folders/Jing/media/33d932c2-955a-4b9b-841e-236f5ce936e8/" allowscriptaccess="always" scale="showall" allowfullscreen="true" flashvars="thumb=http://content.screencast.com/users/lladnar/folders/Jing/media/33d932c2-955a-4b9b-841e-236f5ce936e8/FirstFrame.jpg&amp;containerwidth=763&amp;containerheight=429&amp;content=http://content.screencast.com/users/lladnar/folders/Jing/media/33d932c2-955a-4b9b-841e-236f5ce936e8/00000074.swf&amp;blurover=false" bgcolor="#FFFFFF" quality="high" data="http://content.screencast.com/users/lladnar/folders/Jing/media/33d932c2-955a-4b9b-841e-236f5ce936e8/jingswfplayer.swf"></embed></object></p>
<p>Hopefully you found this useful. I couldn&#8217;t find all of the resources I needed in one place and what I did find wasn&#8217;t detailed enough to solve my problem immediately. This <a href="http://www.cimgf.com/2008/09/04/cocoa-tutorial-creating-your-very-own-framework/">post</a> from Cocoa Is My Girlfriend got me most of the way there and has some more good information on the subject.</p>
]]></content:encoded>
			<wfw:commentRss>http://fredandrandall.com/blog/2011/02/04/how-to-create-a-custom-cocoa-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using blocks and Grand Central Dispatch for asynchronous web calls</title>
		<link>http://fredandrandall.com/blog/2010/11/30/using-blocks-and-grand-central-dispatch-for-asynchronous-web-calls/</link>
		<comments>http://fredandrandall.com/blog/2010/11/30/using-blocks-and-grand-central-dispatch-for-asynchronous-web-calls/#comments</comments>
		<pubDate>Wed, 01 Dec 2010 01:17:17 +0000</pubDate>
		<dc:creator><![CDATA[Randall]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[blocks]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[GCD]]></category>
		<category><![CDATA[Grand Central Dispatch]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[URL shortening]]></category>

		<guid isPermaLink="false">http://fredandrandall.com/blog/?p=180</guid>
		<description><![CDATA[Today at work, we were talking about building a REST framework and someone described how they made NSURLConnection behave synchronously. That seemed strange to me. Then, he told me that using Grand Central Dispatch made it easier to deal with &#8230; <a href="http://fredandrandall.com/blog/2010/11/30/using-blocks-and-grand-central-dispatch-for-asynchronous-web-calls/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://fredandrandall.com/blog/wp-content/uploads/2010/11/gcd_icon200906081.jpg"><img class="alignleft size-full wp-image-188" title="gcd_icon20090608" src="http://fredandrandall.com/blog/wp-content/uploads/2010/11/gcd_icon200906081.jpg" alt="" width="243" height="188" /></a>Today at work, we were talking about building a REST framework and someone described how they made NSURLConnection behave synchronously. That seemed strange to me. Then, he told me that using Grand Central Dispatch made it easier to deal with threads than dealing with the delegate stuff in NSURLConnection.</p>
<p>I&#8217;ve been hearing about how great Grand Central Dispatch is for awhile so when I heard about a practical application of it, I decided to learn about it myself. A little bit of googling led me to a post at <a href="http://cocoasamurai.blogspot.com/2009/09/guide-to-blocks-grand-central-dispatch.html">Cocoa Samurai</a>. It seems to be a pretty good overview of GCD and blocks.</p>
<p>Based on some stuff I learned from there, I built a little demo app that uses GCD and blocks to make synchronous web calls asynchronous.<span id="more-180"></span></p>
<p>The app is a url shortener, if you want to try it out, first you&#8217;ll have to get an API key from bit.ly. (It&#8217;s super easy, just go to <a href="http://bit.ly/a/your_api_key/">http://bit.ly/a/your_api_key/</a> and log in or sign up). Alright, lets get started.</p>
<p><img class="size-medium wp-image-185 aligncenter" title="BlocksScreenShot" src="http://fredandrandall.com/blog/wp-content/uploads/2010/11/BlocksScreenShot-300x118.png" alt="" width="300" height="118" /></p>
<p>First I made a simple UI with a button and a couple of text fields. One is for the URL you&#8217;re going to shorten and the other is for the short URL. Then I hooked up the button to an IBAction called shortenURL:</p>
<p>shortenURL: gets the URL from the first text field and passes it into some blocks that call a synchronous method for shortening the URL and then when that is done, another block updates the UI with the shortened URL. Here&#8217;s the function:</p>
<pre class="brush: objc; title: ; notranslate">
-(IBAction)shortenURL:(id)sender
{
   [spinner startAnimation:nil];

   dispatch_queue_t queue = dispatch_queue_create(&quot;com.Blocks.task&quot;,NULL);
   dispatch_queue_t main = dispatch_get_main_queue();

   dispatch_async(queue,^{
      NSString* shortURL = [self shortenSynchronous:[urlField stringValue]];

      dispatch_async(main,^{
         [self updateUIWithShortURL:shortURL];
      });
   });
}
</pre>
<p>To explain the dispatch_queue_ts you&#8217;ll need to understand a little bit better how GCD works. When you get a new thread from GCD it grabs it from a pool of available threads. When you&#8217;re done with the thread, GCD takes it back so it can be used again. So when you create a thread, you have a little bit of control over where it comes from. This is what the queues are. You create different queues so you can have a little bit of control over what queues your thread dispatches from. At least that is my understanding of this stuff. I could be way wrong.</p>
<p>dispatch_queue_create(&#8220;com.Blocks.task&#8221;, NULL) creates a private queue that is just for my app. dispatch_get_main_queue() gets the main thread for your application.</p>
<p>Next up is dispatching the threads onto the different queues. The first dispatch_async() takes a block that calls the URL shortening function. Then, it dispatches a new block on the main UI thread to update the UI with the result of the url shortening function. It uses what Apple calls recursive decomposition to call it in the right order. I don&#8217;t fully understand how it works yet but the Cocoa Samurai post I talked about earlier goes into more detail.</p>
<p>Other than the UI updating code and the URL shortening code (which is only 3 lines) that is all I needed to do. With an NSURLConnection I&#8217;m stuck implementing delegate methods and appending data as it arrives and some other confusing things. This is much cleaner and shorter. The only problem with it is that I don&#8217;t fully understand how it works&#8230; yet.</p>
<p>You can download the <a href="http://fredandrandall.com/blog/wp-content/uploads/2010/11/Blocks.zip">demo</a> and play with it too. Feel free to use and modify the code.</p>
]]></content:encoded>
			<wfw:commentRss>http://fredandrandall.com/blog/2010/11/30/using-blocks-and-grand-central-dispatch-for-asynchronous-web-calls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Thoughtback, get your thoughts back.</title>
		<link>http://fredandrandall.com/blog/2010/11/11/thoughtback-get-your-thoughts-back/</link>
		<comments>http://fredandrandall.com/blog/2010/11/11/thoughtback-get-your-thoughts-back/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 00:36:34 +0000</pubDate>
		<dc:creator><![CDATA[Randall]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[swlansing]]></category>
		<category><![CDATA[thoughtback]]></category>

		<guid isPermaLink="false">http://fredandrandall.com/blog/?p=151</guid>
		<description><![CDATA[This past weekend I went to an event called Startup Weekend Lansing. Basically, you take a bunch of people with ideas and a bunch of people with the skills to build those ideas and put them all in a room &#8230; <a href="http://fredandrandall.com/blog/2010/11/11/thoughtback-get-your-thoughts-back/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://fredandrandall.com/blog/wp-content/uploads/2010/11/thoughtbackiphone.png"><img class="alignleft size-medium wp-image-157" title="thoughtbackiphone" src="http://fredandrandall.com/blog/wp-content/uploads/2010/11/thoughtbackiphone-156x300.png" alt="" width="156" height="300" /></a><a href="http://fredandrandall.com/blog/wp-content/uploads/2010/11/thoughtbackiphone.png"><br />
</a>This past weekend I went to an event called <a href="http://lansing.startupweekend.org/">Startup Weekend Lansing</a>. Basically, you take a bunch of people with ideas and a bunch of people with the skills to build those ideas and put them all in a room for a weekend. The result of that was several startups.</p>
<p>The result of my weekend? <a href="http://www.thoughtback.com">Thoughtback</a>.</p>
<p>Thoughtback is a personal idea saving/reminding service. Basically, we built an app around the idea that lots of people try to keep track of their thoughts and ideas, but very few ever get to revisit them. So what <a href="http://www.thoughtback.com">thoughtback</a> will do is take your thoughts, then at some later time, send you an email with one of those thoughts so you can revisit the idea.</p>
<p>The service is a webapp, iPhone app, and Mac OSX app. How did we do it in just one weekend?</p>
<p><span id="more-151"></span>We had a pretty skilled team of developers. A few people on the team built the website, and I built the iPhone and Mac apps.</p>
<p>The website backend was written in PHP using CodeIgniter. The email stuff is done using Python and Cron. That stuff is sorta outside my realm of expertise so I&#8217;m glad I got on a team with people that knew what they were doing.</p>
<p>I wrote the iPhone and Mac apps. At first, it might seem like an awful lot to get done in 48 hours, but I was able to do a pretty good job of sharing code between the two apps. For example, all the network communication is done using a cross platform class. Luckily NSURLConnection was one of the things that Apple decided to keep on both platforms. For Keychain access I used a class I found that was actually designed to be used just for iPhone. Unfortunately (although fortunate in my case) the iPhone simulator doesn&#8217;t use the iPhone keychain, it bizarrely uses the Mac keychain. So I was able to use some code (<a href="https://github.com/ldandersen/scifihifi-iphone">SFHFKeychainUtils</a> written by Buzz Anderson) and slightly modify it so it would work on both the iPhone and Mac. Basically I just changed the ifdef from the iPhone simulator to my mac. This let me basically just switch out my view classes and I was good to go.</p>
<p>Anyway, it was an AWESOME weekend and we&#8217;re gonna keep working on it. We even won $1000 bucks to put back into the &#8220;company&#8221; so hopefully we can get some cool stuff into it. We&#8217;ve even been getting some press on local radio stations and in the <a href="http://www.lansingstatejournal.com/article/20101108/NEWS03/11080321/1004/NEWS03">newspaper</a>. The Mac app is available for download RIGHT NOW and the iPhone app is ready to be submitted to the app store. Check it out <a href="http://www.thoughtback.com">www.thoughtback.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://fredandrandall.com/blog/2010/11/11/thoughtback-get-your-thoughts-back/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
