<?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>Carbon Five Community &#187; Xcode</title>
	<atom:link href="http://blog.carbonfive.com/tag/xcode/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.carbonfive.com</link>
	<description></description>
	<lastBuildDate>Fri, 27 Aug 2010 00:24:40 +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>Continuous integration for iPhone projects in TeamCity</title>
		<link>http://blog.carbonfive.com/2010/08/iphone/continuous-integration-for-iphone-projects-in-teamcity</link>
		<comments>http://blog.carbonfive.com/2010/08/iphone/continuous-integration-for-iphone-projects-in-teamcity#comments</comments>
		<pubDate>Sun, 08 Aug 2010 22:58:32 +0000</pubDate>
		<dc:creator>jonah</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=1101</guid>
		<description><![CDATA[Carbon Five has been using TeamCity as our continuous integration server for most of our recent projects, including our iPhone work. Out continuous integration environment monitors the git repository used by each project, runs the project&#8217;s tests each time a change is pushed to the repository, and can automatically produce an ad-hoc build of an [...]]]></description>
			<content:encoded><![CDATA[<p>Carbon Five has been using <a href="http://www.jetbrains.com/teamcity/">TeamCity</a> as our continuous integration server for most of our recent projects, including our iPhone work. Out continuous integration environment monitors the git repository used by each project, runs the project&#8217;s tests each time a change is pushed to the repository, and can automatically produce an ad-hoc build of an app each time the tests pass.<br />
<span id="more-1101"></span><br />
<strong>Configuring the TeamCity build agent</strong><br />
In order to build an iPhone project I need a build runner running on an OS X machine with Xcode installed so I added a remote build agent on a mac mini. Each of the build configurations below then requires that compatible build agents be running on OS X. </p>
<p><strong>Running unit tests with GTM</strong><br />
I have been using <a href="http://code.google.com/p/google-toolbox-for-mac/">GTM</a> to run iPhone unit tests as part of the build process for a &#8220;Unit Tests&#8221; build target (see Alon&#8217;s post on our <a href="http://blog.carbonfive.com/2009/02/testing/iphone-unit-testing-toolkit">iPhone Unit Testing Toolkit)</a>. Running these tests with a TeamCity build agent just requires a command line build runner which calls the `xcodebuild` command and specifies the project, built target, and configuration to build.</p>
<table>
<tbody>
<tr>
<td>Command executable:</td>
<td>/Developer/usr/bin/xcodebuild</td>
</tr>
<tr>
<td>Command parameters:</td>
<td>-project example_project.xcodeproj -target &#8220;Unit Tests&#8221; -configuration &#8220;Debug&#8221; -sdk iphonesimulator4.0</td>
</tr>
</tbody>
<table>
<p><strong>Ad-hoc builds</strong><br />
Ad-hoc builds run with a similar command:</p>
<table>
<tbody>
<tr>
<td>Command executable:</td>
<td>/Developer/usr/bin/xcodebuild</td>
</tr>
<tr>
<td>Command parameters:</td>
<td>-project example_project.xcodeproj -target &#8220;ExampleProject&#8221; -configuration &#8220;Distribution&#8221; -sdk iphoneos4.0</td>
</tr>
</tbody>
<table>
Once the ad-hoc build has been created I want to save the resulting app and its debug symbols so I add these as build artifacts under the TeamCity build configuration&#8217;s General Settings:</p>
<table>
<thead>
<tr>
<th>Artifact paths:</th>
</tr>
</thead>
<tbody>
<tr>
<td>/Users/teamcity/xcode_builds/Distribution-iphoneos/ExampleProject.app => ExampleProject.zip</td>
</tr>
<tr>
<td>/Users/teamcity/xcode_builds/Distribution-iphoneos/ExampleProject.app.dSYM => ExampleProject.app.dSYM.zip</td>
</tr>
</tbody>
</table>
<p>Now my ad-hoc builds are produced automatically, always up to date with my working code changes, and available as an easy download from my TeamCity server. TeamCity will also save the artifacts for each build so I can easily retrieve the dSYM for a particular ad-hoc build to symbolicate a crashlog for that build on any developer&#8217;s machine.</p>
<p><strong>Future improvements</strong><br />
If necessary I can run tests on actual iPhone hardware by changing the sdk (`-sdk iphoneos4.0`) but I am not yet sure how I could specify which one of multiple devices would run the tests. It would be nice to eventually be able to choose between multiple devices so I can deliberately run some tests on a device with a specific OS version or feature set.<br />
With my current configuration TeamCity can only report a pass/fail status for iPhone tests. I need to consider modifying the GTM test runner script or switching to <a href="http://github.com/gabriel/gh-unit">GHUnit</a> or <a href="http://github.com/pivotal/cedar">Cedar</a> to get per-test results and then be able to build up a history of individual test failures.<br />
I also need to add a build configuration which uses agvtool to automatically increment the project&#8217;s build number as part of every ad-hoc build.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2010/08/iphone/continuous-integration-for-iphone-projects-in-teamcity/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Multiple Environments in an iPhone Project</title>
		<link>http://blog.carbonfive.com/2010/02/iphone/multiple-environments-in-an-iphone-project</link>
		<comments>http://blog.carbonfive.com/2010/02/iphone/multiple-environments-in-an-iphone-project#comments</comments>
		<pubDate>Sat, 13 Feb 2010 03:02:31 +0000</pubDate>
		<dc:creator>jonah</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=823</guid>
		<description><![CDATA[I&#8217;ve been following a Rails convention and defining multiple environments for my iPhone projects. This allows me to quickly switch application wide settings when running a test, development, or production version of the app. I already have build targets for each environment as part of the unit testing setup I have been using so adding [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been following a Rails convention and defining multiple environments for my iPhone projects. This allows me to quickly switch application wide settings when running a test, development, or production version of the app.<br />
<span id="more-823"></span><br />
I already have build targets for each environment as part of the unit testing setup I have been using so adding target-specific run-time settings turns out to be quite easy.</p>
<p>I created an &#8220;Environments&#8221; resource group in Xcode and added a copy of my project&#8217;s &#8220;Resource/Info.plist&#8221; file for each environment.</p>
<div id="attachment_834" class="wp-caption alignnone" style="width: 196px"><img class="size-full wp-image-834 " title="environment_plists" src="http://blog.carbonfive.com/wp-content/uploads/2010/02/Screen-shot-2010-02-12-at-6.17.12-PM.png" alt="Environment specific plist files in the project." width="186" height="104" /><p class="wp-caption-text">A plist for each environment.</p></div>
<p>These plists should not be members of any build target (just like the original Info.plist.</p>
<div id="attachment_841" class="wp-caption alignnone" style="width: 415px"><img class="size-full wp-image-841 " title="info_plist_targets" src="http://blog.carbonfive.com/wp-content/uploads/2010/02/Screen-shot-2010-02-12-at-6.17.47-PM1.png" alt="Info.plist files are not members of any build targets." width="405" height="173" /><p class="wp-caption-text">Info.plist files should not  be members of a build target.</p></div>
<p>In each build target&#8217;s settings I then set the &#8220;Info.plist File&#8221; to the plist I created for that target&#8217;s environment. Note that the path to this file is the actual path on disk relative to the project root; if you have an &#8216;Environments&#8217; group in the project but no actual &#8216;Environments&#8217; directory in your project then this path would be incorrect.</p>
<div id="attachment_836" class="wp-caption alignnone" style="width: 286px"><a href="http://blog.carbonfive.com/wp-content/uploads/2010/02/Screen-shot-2010-02-12-at-6.18.52-PM.png"><img class="size-full wp-image-836   " title="built_target_plist_settings" src="http://blog.carbonfive.com/wp-content/uploads/2010/02/Screen-shot-2010-02-12-at-6.18.52-PM.png" alt="Specifying a plist file in the build target settings." width="276" height="336" /></a><p class="wp-caption-text">Specifying the  plist for a build target.</p></div>
<p>In code I can then access the plist&#8217;s dictionary via the application bundle:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> infoDictionary<span style="color: #002200;">&#93;</span></pre></div></div>

<p>Now I can define the domain name of an API I will be using in each plist and automatically connect to localhost when running tests, to a staging server when using a development build, and to the production server when building a release or adhoc build. Each environment has it&#8217;s own build target so I can also specify a different app product identifier for each target and install the different app versions side by side on the same device.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2010/02/iphone/multiple-environments-in-an-iphone-project/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Code Formatting in Xcode</title>
		<link>http://blog.carbonfive.com/2009/08/iphone/code-formatting-in-xcode</link>
		<comments>http://blog.carbonfive.com/2009/08/iphone/code-formatting-in-xcode#comments</comments>
		<pubDate>Fri, 07 Aug 2009 23:37:39 +0000</pubDate>
		<dc:creator>jonah</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=658</guid>
		<description><![CDATA[Working in Xcode I almost forgot how much I like IntelliJ&#8217;s code formatting tools. Luckily for me Mike Smith recently pointed out that UniversalIndentGUI can be used to setup your own code formatting in Xcode. UniversalIndentGUI supports a large number of code formatting tools but Uncrustify seems to be the only one with objective-c support. An up [...]]]></description>
			<content:encoded><![CDATA[<p>Working in Xcode I almost forgot how much I like IntelliJ&#8217;s code formatting tools. Luckily for me <a href="https://devforums.apple.com/people/MikeSmith">Mike Smith</a> recently pointed out that <a href="http://universalindent.sourceforge.net/index.php">UniversalIndentGUI</a> can be used to setup your own code formatting in Xcode.<br />
<span id="more-658"></span><br />
UniversalIndentGUI supports a large number of code formatting tools but <a href="http://uncrustify.sourceforge.net/">Uncrustify</a> seems to be the only one with objective-c support. An up to date build of Uncrustify (version 0.53) is included with UniversalIndentGUI so I did not need to build my own.</p>
<p>I setup a set of styling rules using UniversalIndentGUI&#8217;s live preview and saved the resulting config file. I was then able to add a set of custom user scripts in Xcode to run Uncrustify against the current file or selection. I found that I had to specify the source as objective-c to prevent Uncrustify form running some C/C++ styling rules which I did not want.</p>
<div id="attachment_660" class="wp-caption alignnone" style="width: 510px"><a href="http://blog.carbonfive.com/wp-content/uploads/2009/08/uncrustify-scripts.png"><img class="size-full wp-image-660" title="uncrustify-scripts" src="http://blog.carbonfive.com/wp-content/uploads/2009/08/uncrustify-scripts.png" alt="Uncrustify custom scripts in Xcode" width="500" height="332" /></a><p class="wp-caption-text">Uncrustify custom scripts in Xcode</p></div>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
~<span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>UniversalIndentGUI<span style="color: #000000; font-weight: bold;">/</span>indenters<span style="color: #000000; font-weight: bold;">/</span>uncrustify <span style="color: #660033;">-l</span> OC <span style="color: #660033;">-q</span> <span style="color: #660033;">-c</span> ~<span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>UniversalIndentGUI<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span>uncrustify_obj_c.cfg</pre></div></div>

<p>Now I can quickly clean up most of the minor formatting inconsistencies which creep into my code. Now I just need to polish my config file until it better matches my expectations for code formatting. In defining my preferred code style I have tried to follow the example provided by:</p>
<ul>
<li><a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html">Coding Guidelines for Cocoa</a></li>
<li><a href="http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml">Google Objective-C Style Guide</a></li>
<li><a href="http://www.cocoadevcentral.com/articles/000082.php">Cocoa Style for Objective-C</a></li>
</ul>
<p>My current config file for Uncrustify is available here: <a href="http://svn.carbonfive.com/public/jonah/UniversalIndentGUI/config/uncrustify_obj_c.cfg">uncrustify_obj_c.cfg</a> if you would like to use it as a starting point.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2009/08/iphone/code-formatting-in-xcode/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Custom Xcode Templates for iPhone Development</title>
		<link>http://blog.carbonfive.com/2009/05/testing/custom-xcode-template-for-iphone-development</link>
		<comments>http://blog.carbonfive.com/2009/05/testing/custom-xcode-template-for-iphone-development#comments</comments>
		<pubDate>Wed, 20 May 2009 00:25:16 +0000</pubDate>
		<dc:creator>jonah</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=534</guid>
		<description><![CDATA[Previously we discussed building an iPhone Unit Testing Toolkit. I wanted to reuse that work without having to repeat those configuration steps every time I started a new Xcode project. Xcode provides a number of templates or starting iPhone applications so I made my own versions which include all of the unit testing tools we rely [...]]]></description>
			<content:encoded><![CDATA[<p>Previously we discussed building an <a title="iPhone Unit Testing Toolkit" rel="bookmark" href="http://blog.carbonfive.com/2009/02/testing/iphone-unit-testing-toolkit" target="_self">iPhone Unit Testing Toolkit</a>. I wanted to reuse that work without having to repeat those configuration steps every time I started a new Xcode project. Xcode provides a number of templates or starting iPhone applications so I made my own versions which include all of the unit testing tools we rely on.</p>
<p><span id="more-534"></span></p>
<p>To reuse my templates checkout a copy from <a href="http://svn.carbonfive.com/public/jonah/Xcode-templates/Xcode/">http://svn.carbonfive.com/public/jonah/Xcode-templates/Xcode/</a> to &#8220;/Library/Application Support/Developer/Shared/Xcode/&#8221; and restart Xcode.</p>
<h2>Installing the template files:</h2>
<p>I installed Apple&#8217;s developer tools using the default path so my copy of Apple&#8217;s Xcode templates is located in &#8220;/Developer/Library/Xcode/File Templates&#8221; and &#8220;/Developer/Library/Xcode/Project Templates&#8221;. Installing the iPhone SDK added additional templates in &#8220;/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/&#8221;. Those were useful examples to base my own templates on but I needed to save my new templates separate from Apple&#8217;s default configuration files.</p>
<p>The <a title="Xcode Release Notes" href="http://developer.apple.com/releasenotes/developertools/RN-Xcode/index.html" target="_blank">Xcode release notes</a> state that custom support files including project and file templates belong under &#8220;/Library/Application Support/Developer/&#8221; or &#8220;~/Library/Application Support/Developer/&#8221;. I didn&#8217;t need to restrict the visibility of these templates to a specific version of Xcode and I wanted them to be available to any user account so I put them in &#8220;/Library/Application Support/Developer/Shared/Xcode/Project Templates&#8221; and &#8220;/Library/Application Support/Developer/Shared/Xcode/File Templates&#8221;.</p>
<h2>Building a template project:</h2>
<div>
<p>I started by adding a &#8220;test&#8221; build target to Apple&#8217;s default &#8220;View-Based Application&#8221; template. First I copied &#8220;/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application/View-Based Application&#8221; to &#8220;/Library/Application Support/Developer/Shared/Xcode/Project Templates/Carbon Five/Testable View-Based Application&#8221;. Then I opened &#8220;Testable View-Based Application/___PROJECTNAME___.xcodeproj&#8221; in Xcode and changed the customized the project structure by adding a &#8220;Unit Tests&#8221; target, the hamcrest and OCMock frameworks, GTM classes, an example test class, and a couple of groups in the overview list.</p>
<div>
<p><a href="http://blog.carbonfive.com/wp-content/uploads/2009/03/customized_project.png"><img class="size-medium wp-image-543 alignnone" title="customized_project" src="http://blog.carbonfive.com/wp-content/uploads/2009/03/customized_project.png" alt="Custom project settings" width="300" height="275" /></a></div>
<div>While setting up the project and testing its configuration Xcode created a bunch of files I did not want as part of my template so when I finished with the project I deleted both the build products directory and the user specific settings files inside the &#8221;___PROJECTNAME___.xcodeproj&#8221; package. I also editted the template description in &#8220;TemplateInfo.plist&#8221;.</div>
<div>I restarted Xcode and could start a new project using the template by selecting it from the User Templates section of the New Project dialog.</div>
<p><a href="http://blog.carbonfive.com/wp-content/uploads/2009/03/selecting_user_template.png"><img class="alignnone size-medium wp-image-545" title="selecting_user_template" src="http://blog.carbonfive.com/wp-content/uploads/2009/03/selecting_user_template.png" alt="" width="300" height="230" /></a><a href="http://blog.carbonfive.com/wp-content/uploads/2009/03/project_from_template.png"><img class="alignnone size-medium wp-image-546" title="project_from_template" src="http://blog.carbonfive.com/wp-content/uploads/2009/03/project_from_template.png" alt="" width="300" height="253" /></a></p>
<h2>Creating a file template:</h2>
<p>Creating a project from my template was handy but I wanted a faster way to build individual test classes as well so I wrote a file template.</p>
<p>First I copied &#8220;/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/File Templates/Cocoa Touch Classes/NSObject subclass.pbfiletemplate&#8221; to &#8220;/Library/Application Support/Developer/Shared/Xcode/File Templates/Carbon Five/GTM test template.pbfiletemplate&#8221;. Then in the class.m file I added hamcrest and OCMock imports and an example test method. This class did not require a separate header file so I deleted class.h.</p>
<p><a href="http://blog.carbonfive.com/wp-content/uploads/2009/03/class_m.png"><img class="alignnone size-medium wp-image-553" title="class_m" src="http://blog.carbonfive.com/wp-content/uploads/2009/03/class_m.png" alt="" width="300" height="158" /></a></p>
<p>In TemplateInfo.plist I updated the template&#8217;s description and since I removed the header file I removed the CounterpartTemplateFile line.</p>
<p><a href="http://blog.carbonfive.com/wp-content/uploads/2009/03/templateinfo_plist.png"><img class="alignnone size-medium wp-image-549" title="templateinfo_plist" src="http://blog.carbonfive.com/wp-content/uploads/2009/03/templateinfo_plist.png" alt="" width="300" height="163" /></a></p>
<p>After restart Xcode again I could create test classes based on the template using the &#8220;New File&#8230;&#8221; menu.</p>
<p><a href="http://blog.carbonfive.com/wp-content/uploads/2009/03/test_from_template.png"></a><a href="http://blog.carbonfive.com/wp-content/uploads/2009/03/selecting_file_template.png"><img class="alignnone size-medium wp-image-555" title="selecting_file_template" src="http://blog.carbonfive.com/wp-content/uploads/2009/03/selecting_file_template.png" alt="" width="300" height="230" /></a><img class="alignnone size-medium wp-image-550" title="test_from_template" src="http://blog.carbonfive.com/wp-content/uploads/2009/03/test_from_template.png" alt="" width="317" height="200" /></p>
<p>A couple dozen unit tests later I&#8217;m happy not to be repeating even this minimal amount of configuration each time I start a new test.</p>
<p>If you&#8217;re developing in Xcode I&#8217;d like to hear what sort of project setup you use. Are there libraries or frameworks you always include? Class files you have, or wish you had, created templates for? Do you use Apple&#8217;s default resource groups or have you established your own conventions for organizing your projects?</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2009/05/testing/custom-xcode-template-for-iphone-development/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
