<?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>The Carbon Emitter &#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>The blog of Carbon Five</description>
	<lastBuildDate>Mon, 23 Jan 2012 18:38:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Managing iOS Configurations per Environment in Xcode 4</title>
		<link>http://blog.carbonfive.com/2011/06/20/managing-ios-configurations-per-environment-in-xcode-4/</link>
		<comments>http://blog.carbonfive.com/2011/06/20/managing-ios-configurations-per-environment-in-xcode-4/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 10:16:34 +0000</pubDate>
		<dc:creator>Rob Pak</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=3545</guid>
		<description><![CDATA[At Carbon Five we usually have 3 &#8211; 4 environments our iOS applications will run against: development, acceptance, staging and production. Often, the property values that are unique across environments are URLs to APIs that we are integrating with. There &#8230; <a href="http://blog.carbonfive.com/2011/06/20/managing-ios-configurations-per-environment-in-xcode-4/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>At Carbon Five we usually have 3 &#8211; 4 environments our iOS applications will run against: development, acceptance, staging and production. Often, the property values that are unique across environments are URLs to APIs that we are integrating with. There have been several approaches for managing different configurations per environment. Some have included <a href="http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/115-Configuring_Applications/configuring_applications.html" target="_">conditional compilation</a> or build-time file substitution. While all are valid approaches, I opted to use Xcode&#8217;s build configurations to manage configurations per environment. Here is how I did it:</p>
<h2>Step 1: Modify Your Default PList File</h2>
<p>Your default plist file is usually named ${PRODUCT_NAME}-Info.plist and is located beneath the &#8220;Supporting Files&#8221; group of your Xcode project. Add a new row/item of type <em>String</em> to the plist file and name it <em>Configuration</em>. Set the value to be <em>${CONFIGURATION}</em>, the Xcode provided environment variable for the current build configuration.</p>
<p><a href="http://blog.carbonfive.com/wp-content/uploads/2011/05/infoplist.png"><img class="size-full wp-image-3555" title="InfoPlist" src="http://blog.carbonfive.com/wp-content/uploads/2011/05/infoplist.png" alt="" width="640" height="330" /></a></p>
<p><span id="more-3545"></span></p>
<h2>Step 2: Create a Custom Environments.plist File to Store Configuration Data</h2>
<p>Right-click on the &#8220;Supporting Files&#8221; group and select &#8220;New File&#8221; (New File &gt; Resource &gt; Property List). Save File as &#8220;Environments&#8221;, this will create a file named &#8220;Environments.plist&#8221;. Now that you have your custom plist file ready to be modified, add all of your build configurations (Debug and Release by default) of type Dictionary to the plist. You can also begin to enter custom properties underneath each build configuration (entered as myAPIURL in my example).</p>
<p>Optionally, you can segregate your property files per build configuration. For example, create plist files for each of your build configurations (i.e. Debug.plist, Release.plist).</p>
<p><a href="http://blog.carbonfive.com/wp-content/uploads/2011/05/environments.png"><img class="alignnone size-full wp-image-3559" title="Environments" src="http://blog.carbonfive.com/wp-content/uploads/2011/05/environments.png" alt="Add Custom Properties to Configuration by Environment (Build Configuration)" width="640" height="274" /></a></p>
<h2>Step 3: Make your Custom Configuration Available to your Application</h2>
<p>Create a singleton or implement a strategy to load your configuration data on a per build configuration basis. You can determine your scheme&#8217;s current build configuration by reading the &#8220;Configuration&#8221; property within your default plist file (as applied in step one).</p>
<p>For example, here is a singleton that will load your configuration:<br />
<script src="https://gist.github.com/1032532.js?file=Environment.m"></script></p>
<p>Now you should be able to access properties within your application by sending getter messages to the Environment instance.</p>
<p><pre class="brush: objc; title: ; notranslate">
Environment *myEnvironment = [Environment sharedInstance];
NSString *apiURL = myEnvironment.myApiURL;
</pre>
</p>
<h2>Step 4: Add Additional Build Configurations to your Application</h2>
<p>Within Xcode, select your Project within the left-hand navigation. Your project and target settings should be visible and editable. Next, select your project settings so that your build configurations are exposed (by default, Xcode creates the Debug and Release build configurations for you). At this point you can create a new build configuration for a custom environment (i.e. acceptance, staging or demo).</p>
<p><a href="http://blog.carbonfive.com/wp-content/uploads/2011/05/project.png"><img class="size-full wp-image-3574" title="project" src="http://blog.carbonfive.com/wp-content/uploads/2011/05/project.png" alt="" width="640" height="286" /></a></p>
<p>
 Also, don&#8217;t forget to add your custom configuration data for your new build configuration.
</p>
<p><a href="http://blog.carbonfive.com/wp-content/uploads/2011/05/acceptance.png"><img class="size-full wp-image-3575" title="acceptance" src="http://blog.carbonfive.com/wp-content/uploads/2011/05/acceptance.png" alt="" width="640" height="220" /></a></p>
<h2>Now Your Ready!</h2>
<p>Your application now has access to configurations per environment by use of build configurations. We&#8217;ve made the current build configuration readable by adding it to the default plist file. We used the current build configuration as an identifier for key&#8217;ing entries in a custom properties file (Environments.plist). The custom properties file contains configuration properties per build configuration. In order to read the custom properties programmatically, we created an object (Environment.m) to read the file. Finally, we added custom build configurations to support new, application specific, environments.</p>
<p>Some side notes:</p>
<ul>
<li>One target, configurable schemes: You can change the build configuration you would like to use for a target by editing (or creating) your scheme. This will quickly allow you to run your target against different application environments.</li>
<li>Properties like bundle identifier and bundle name can be set by user defined properties and further specified by your build configurations. This will make deploying you application to devices easier.</li>
<li>The Xcode command line build tool has a parameter named &#8220;configuration&#8221;. This will allow you to build your application per environment (i.e. xcodebuild -configuration Debug).</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2011/06/20/managing-ios-configurations-per-environment-in-xcode-4/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Debug logging with Xcode 4 breakpoints</title>
		<link>http://blog.carbonfive.com/2011/06/16/debug-logging-with-xcode-4-breakpoints/</link>
		<comments>http://blog.carbonfive.com/2011/06/16/debug-logging-with-xcode-4-breakpoints/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 00:12:04 +0000</pubDate>
		<dc:creator>Jonah Williams</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=4111</guid>
		<description><![CDATA[NSLog calls do not belong in release builds. Logging is slow and the performance impact of log statements on a device can be considerable. Logging is also noisy, it can obscure useful debugging information and may leak information you would &#8230; <a href="http://blog.carbonfive.com/2011/06/16/debug-logging-with-xcode-4-breakpoints/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>NSLog calls do not belong in release builds. Logging is slow and the performance impact of log statements on a device can be considerable. Logging is also noisy, it can obscure useful debugging information and may leak information you would rather not expose in a release build. Looking at my device&#8217;s system log I see output full of content urls, api keys, massive log messages, and data only valuable while debugging an app.</p>
<blockquote><p>: Succeeded! Received 18977 bytes of data for url http://www&#8230;<br />
: fetched comments: ( &#8230;&lt;74k of JSON&gt;<br />
: *** &#8230;GetData: http://&#8230;/query?id=1001&amp;sc=17&amp;fields=&#8230;&amp;apiKey=<br />
: applicationDidBecomeActive completed<br />
: JSON parsing finished in 24 ms. String alloc took 2 ms. Comment stripping took 1 ms.<br />
: CallbackHandler registered delegate,, instance=0&#215;263650</p></blockquote>
<p>There are a number of examples of using precompiler macros to eliminate log output on non-debug builds but I recently started using Xcode 4&#8242;s breakpoints and find them to be my favorite mechanism. Breakpoints can be configured to log arbitrary output and automatically continue to avoid stopping program execution. They can be dragged from one line to another, added, disabled, and removed while your app is running. You can even check them in as part of your project to share them with other developers.<br />
<span id="more-4111"></span></p>
<p><strong>Console logging with breakpoints</strong><br />
Create a new breakpoint by clicking in the source editor&#8217;s gutter.<br />
Control-click the breakpoint to edit its behavior.<br />
<a rel="attachment wp-att-4113" href="http://blog.carbonfive.com/2011/06/16/debug-logging-with-xcode-4-breakpoints/edit_breakpoint/"><img class="alignnone size-full wp-image-4113" title="edit_breakpoint" src="http://blog.carbonfive.com/wp-content/uploads/2011/06/edit_breakpoint.png" alt="" width="498" height="273" /></a><br />
When hit the example breakpoint above will log <code>-didReceiveMemoryWarning my title is "Demo!"</code> to the console.</p>
<p><strong>Sharing breakpoints</strong><br />
In the breakpoint navigator control-click a breakpoint to share it as part of a workspace.<br />
Shared breakpoints are stored in .xcworkspace/xcshareddata/xcdebugger/Breakpoints.xcbkptlist<br />
<a rel="attachment wp-att-4114" href="http://blog.carbonfive.com/2011/06/16/debug-logging-with-xcode-4-breakpoints/share_breakpoint/"><img class="alignnone size-full wp-image-4114" title="share_breakpoint" src="http://blog.carbonfive.com/wp-content/uploads/2011/06/share_breakpoint.png" alt="" width="457" height="320" /></a><br />
<a rel="attachment wp-att-4115" href="http://blog.carbonfive.com/2011/06/16/debug-logging-with-xcode-4-breakpoints/shared_breakpoint/"><img class="alignnone size-full wp-image-4115" title="shared_breakpoint" src="http://blog.carbonfive.com/wp-content/uploads/2011/06/shared_breakpoint.png" alt="" width="490" height="290" /></a><br />
I&#8217;ve found breakpoints to be a great way to log debug information about the app in a configuration which I can choose to share with my team and which runs no risk of appearing in a release build. The breakpoints navigator gives me an easy way to jump to any of these log statements and it is trivial to switch a breakpoint from just logging to pausing the app so I can debug in depth. I&#8217;ll still use NSLog for exceptional conditions I want to report in any build but so far you won&#8217;t find a single one in my current project.</p>
<p>Have you found a NSLog alternative you are happy with? Is there anything you couldn&#8217;t replace with logging breakpoints instead?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2011/06/16/debug-logging-with-xcode-4-breakpoints/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Automated ad hoc builds using Xcode 4</title>
		<link>http://blog.carbonfive.com/2011/05/04/automated-ad-hoc-builds-using-xcode-4/</link>
		<comments>http://blog.carbonfive.com/2011/05/04/automated-ad-hoc-builds-using-xcode-4/#comments</comments>
		<pubDate>Wed, 04 May 2011 23:24:19 +0000</pubDate>
		<dc:creator>Jonah Williams</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[teamcity]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=3521</guid>
		<description><![CDATA[I&#8217;ve previously discussed Continuous Integration for iPhone Projects in TeamCity using Xcode 3 and Building Xcode 4 Projects from the Command Line. Now I&#8217;ll tie those together and use TeamCity to automatically create ad hoc builds I can install over &#8230; <a href="http://blog.carbonfive.com/2011/05/04/automated-ad-hoc-builds-using-xcode-4/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve previously discussed <a href="http://blog.carbonfive.com/2010/08/08/continuous-integration-for-iphone-projects-in-teamcity/">Continuous Integration for iPhone Projects in TeamCity</a> using Xcode 3 and <a href="http://blog.carbonfive.com/2011/04/06/building-xcode-4-projects-from-the-command-line/">Building Xcode 4 Projects from the Command Line</a>. Now I&#8217;ll tie those together and use TeamCity to automatically create ad hoc builds I can install over the air (directly onto a device without using iTunes) every time I check in code.</p>
<p><span id="more-3521"></span></p>
<p>I created a basic project configuration in TeamCity 6 to checkout my iOS project from git.</p>
<p>I set the artifact paths for this configuration to</p>
<blockquote><p>
project_name.acceptance.app*<br />
ad_hoc/*.png
</p></blockquote>
<p>This will eventually allow TeamCity to collect the icons, project_name.acceptance.app.ipa, and project_name.acceptance.app.plist files needed to perform an over the air install of the ad hoc build.</p>
<p>Finally I created the following custom script build step (available as <a href="https://gist.github.com/949831">https://gist.github.com/949831</a>).</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash

# https://gist.github.com/949831
# http://blog.carbonfive.com/2011/05/04/automated-ad-hoc-builds-using-xcode-4/

# command line OTA distribution references and examples
# http://nachbaur.com/blog/how-to-automate-your-iphone-app-builds-with-hudson
# http://nachbaur.com/blog/building-ios-apps-for-over-the-air-adhoc-distribution
# http://blog.octo.com/en/automating-over-the-air-deployment-for-iphone/
# http://www.neat.io/posts/2010/10/27/automated-ota-ios-app-distribution.html

project_dir=`pwd`

# Configuration
environment_name=&quot;staging&quot;
keychain=&quot;ci_keys&quot;
keychain_password=&quot;super secret&quot;
workspace=&quot;MyApp.xcworkspace&quot;
scheme=&quot;Ad Hoc&quot;
info_plist=&quot;$project_dir/MyApp-Info.plist&quot;
environment_plist=&quot;$environment_name.plist&quot;
environment_info_plist=&quot;$environment_name-Info.plist&quot;
product_name=&quot;My App $environment_name&quot;
mobileprovision=&quot;$project_dir/ad_hoc/MyAppStaging.mobileprovision&quot;
provisioning_profile=&quot;iPhone Distribution: My Company, LLC&quot;
build_number=&quot;%env.BUILD_NUMBER%&quot;
artifacts_url=&quot;http://my_ci_server.example/artifacts/$build_number&quot;
display_image_name=&quot;Icon-57.png&quot;
full_size_image_name=&quot;Icon-512.png&quot;

function failed()
{
    local error=${1:-Undefined error}
    echo &quot;Failed: $error&quot; &gt;&amp;2
    exit 1
}

function validate_keychain()
{
  # unlock the keychain containing the provisioning profile's private key and set it as the default keychain
  security unlock-keychain -p &quot;$keychain_password&quot; &quot;$HOME/Library/Keychains/$keychain.keychain&quot;
  security default-keychain -s &quot;$HOME/Library/Keychains/$keychain.keychain&quot;

  #describe the available provisioning profiles
  echo &quot;Available provisioning profiles&quot;
  security find-identity -p codesigning -v

  #verify that the requested provisioning profile can be found
  (security find-certificate -a -c &quot;$provisioning_profile&quot; -Z | grep ^SHA-1) || failed provisioning_profile
}

function describe_sdks()
{
  #list the installed sdks
  echo &quot;Available SDKs&quot;
  xcodebuild -showsdks
}

function describe_workspace()
{
  #describe the project workspace
  echo &quot;Available schemes&quot;
  xcodebuild -list -workspace $workspace
}

function increment_version()
{
  cd &quot;MyApp&quot;
  agvtool -noscm new-version -all $build_number
  cd ..
}

function set_environment()
{
  #copy the info plist for the selected environment into place
  cp -v &quot;MyApp/$environment_info_plist&quot; $info_plist || failed environment_plist
  #copy the environment settings plist into place
  cp -v &quot;MyApp/$environment_plist&quot; &quot;MyApp/environment.plist&quot; || failed environment

  #extract settings from the Info.plist file
  info_plist_domain=$(ls $info_plist | sed -e 's/\.plist//')
  short_version_string=$(defaults read &quot;$info_plist_domain&quot; CFBundleShortVersionString)
  bundle_identifier=$(defaults read &quot;$info_plist_domain&quot; CFBundleIdentifier)
  echo &quot;Environment set to $bundle_identifier at version $short_version_string&quot;
}

function build_app()
{
  local devired_data_path=&quot;$HOME/Library/Developer/Xcode/DerivedData&quot;

  #get the name of the workspace to be build, used as the prefix of the DerivedData directory for this build
  local workspace_name=$(echo &quot;$workspace&quot; | sed -n 's/\([^\.]\{1,\}\)\.xcworkspace/\1/p')
  #build the app
  echo &quot;Running xcodebuild &gt; xcodebuild_output ...&quot;

#  disabled overriding PRODUCT_NAME, setting applies to all built targets in Xcode 4 which renames static library target dependencies and breaks linking
#  xcodebuild -verbose -workspace &quot;$workspace&quot; -scheme &quot;$scheme&quot; -sdk iphoneos -configuration Release clean build PRODUCT_NAME=&quot;$product_name&quot; &gt;| xcodebuild_output
  xcodebuild -verbose -workspace &quot;$workspace&quot; -scheme &quot;$scheme&quot; -sdk iphoneos -configuration Release clean build &gt;| xcodebuild_output

  if [ $? -ne 0 ]
  then
    tail -n20 xcodebuild_output
    failed xcodebuild
  fi

  #locate this project's DerivedData directory
  local project_derived_data_directory=$(grep -oE &quot;$workspace_name-([a-zA-Z0-9]+)[/]&quot; xcodebuild_output | sed -n &quot;s/\($workspace_name-[a-z]\{1,\}\)\//\1/p&quot; | head -n1)
  local project_derived_data_path=&quot;$devired_data_path/$project_derived_data_directory&quot;
  #locate the .app file

#  infer app name since it cannot currently be set using the product name, see comment above
#  project_app=&quot;$product_name.app&quot;
  project_app=$(ls -1 &quot;$project_derived_data_path/Build/Products/Release-iphoneos/&quot; | grep &quot;.*\.app$&quot; | head -n1)

  # if [ $(ls -1 &quot;$project_derived_data_path/Build/Products/Release-iphoneos/$project_app&quot; | wc -l) -ne 1 ]
  if [ $(ls -1 &quot;$project_derived_data_path/Build/Products/Release-iphoneos/&quot; | grep &quot;.*\.app$&quot; | wc -l) -ne 1 ]
  then
    echo &quot;Failed to find a single .app build product.&quot;
    # echo &quot;Failed to locate $project_derived_data_path/Build/Products/Release-iphoneos/$project_app&quot;
    failed locate_built_product
  fi
  echo &quot;Built $project_app in $project_derived_data_path&quot;

  #copy app and dSYM files to the working directory
  cp -Rf &quot;$project_derived_data_path/Build/Products/Release-iphoneos/$project_app&quot; $project_dir
  cp -Rf &quot;$project_derived_data_path/Build/Products/Release-iphoneos/$project_app.dSYM&quot; $project_dir

  #rename app and dSYM so that multiple environments with the same product name are identifiable
  echo &quot;Retrieving build products...&quot;
  rm -rf $project_dir/$bundle_identifier.app
  rm -rf $project_dir/$bundle_identifier.app.dSYM
  mv -f &quot;$project_dir/$project_app&quot; &quot;$project_dir/$bundle_identifier.app&quot;
  echo &quot;$project_dir/$bundle_identifier.app&quot;
  mv -f &quot;$project_dir/$project_app.dSYM&quot; &quot;$project_dir/$bundle_identifier.app.dSYM&quot;
  echo &quot;$project_dir/$bundle_identifier.app.dSYM&quot;
  project_app=$bundle_identifier.app

  #relink CodeResources, xcodebuild does not reliably construct the appropriate symlink
  rm &quot;$project_app/CodeResources&quot;
  ln -s &quot;$project_app/_CodeSignature/CodeResources&quot; &quot;$project_app/CodeResources&quot;
}

function sign_app()
{
  echo &quot;Codesign as \&quot;$provisioning_profile\&quot;, embedding provisioning profile $mobileprovision&quot;
  #sign build for distribution and package as a .ipa
  xcrun -sdk iphoneos PackageApplication &quot;$project_dir/$project_app&quot; -o &quot;$project_dir/$project_app.ipa&quot; --sign &quot;$provisioning_profile&quot; --embed &quot;$mobileprovision&quot; || failed codesign
}

function verify_app()
{
  #verify the resulting app
  codesign -d -vvv --file-list - &quot;$project_dir/$project_app&quot; || failed verification
}

function build_ota_plist()
{
  echo &quot;Generating $project_app.plist&quot;
  cat &lt;&lt; EOF &gt; $project_app.plist
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;
&lt;plist version=&quot;1.0&quot;&gt;
&lt;dict&gt;
  &lt;key&gt;items&lt;/key&gt;
  &lt;array&gt;
    &lt;dict&gt;
      &lt;key&gt;assets&lt;/key&gt;
      &lt;array&gt;
        &lt;dict&gt;
          &lt;key&gt;kind&lt;/key&gt;
          &lt;string&gt;software-package&lt;/string&gt;
          &lt;key&gt;url&lt;/key&gt;
          &lt;string&gt;$artifacts_url/$project_app.ipa&lt;/string&gt;
        &lt;/dict&gt;
        &lt;dict&gt;
          &lt;key&gt;kind&lt;/key&gt;
          &lt;string&gt;full-size-image&lt;/string&gt;
          &lt;key&gt;needs-shine&lt;/key&gt;
          &lt;true/&gt;
          &lt;key&gt;url&lt;/key&gt;
          &lt;string&gt;$artifacts_url/$full_size_image_name&lt;/string&gt;
        &lt;/dict&gt;
        &lt;dict&gt;
          &lt;key&gt;kind&lt;/key&gt;
          &lt;string&gt;display-image&lt;/string&gt;
          &lt;key&gt;needs-shine&lt;/key&gt;
          &lt;true/&gt;
          &lt;key&gt;url&lt;/key&gt;
          &lt;string&gt;$artifacts_url/$display_image_name&lt;/string&gt;
        &lt;/dict&gt;
      &lt;/array&gt;
      &lt;key&gt;metadata&lt;/key&gt;
      &lt;dict&gt;
        &lt;key&gt;bundle-identifier&lt;/key&gt;
        &lt;string&gt;$bundle_identifier&lt;/string&gt;
        &lt;key&gt;bundle-version&lt;/key&gt;
        &lt;string&gt;$short_version_string $build_number&lt;/string&gt;
        &lt;key&gt;kind&lt;/key&gt;
        &lt;string&gt;software&lt;/string&gt;
        &lt;key&gt;subtitle&lt;/key&gt;
        &lt;string&gt;$environment_name&lt;/string&gt;
        &lt;key&gt;title&lt;/key&gt;
        &lt;string&gt;$project_app&lt;/string&gt;
      &lt;/dict&gt;
    &lt;/dict&gt;
  &lt;/array&gt;
&lt;/dict&gt;
&lt;/plist&gt;
EOF
}

echo &quot;**** Validate Keychain&quot;
validate_keychain
echo
echo &quot;**** Describe SDKs&quot;
describe_sdks
echo
echo &quot;**** Describe Workspace&quot;
describe_workspace
echo
echo &quot;**** Set Environment&quot;
set_environment
echo
echo &quot;**** Increment Bundle Version&quot;
increment_version
echo
echo &quot;**** Build&quot;
build_app
echo
echo &quot;**** Package Application&quot;
sign_app
echo
echo &quot;**** Verify&quot;
verify_app
echo
echo &quot;**** Prepare OTA Distribution&quot;
build_ota_plist
echo
echo &quot;**** Complete!&quot;
</pre>
<p>That is quite a few functions but the bottom of the script steps through them in what is hopefully an understandable sequence.</p>
<ol>
<li>Unlock the keychain containing the private key and provisioning profile used to sign the ad hoc build. Necessary since the TeamCity user&#8217;s login keychain may be locked when this build runs.</li>
<li>List the available sdks on the build machine (unnecessary but I found it helpful when debugging build settings).</li>
<li>List the schemes found in the workspace to be built (again purely for debugging).</li>
<li>Copy a plist containing application settings to &#8220;environment.plist&#8221; which will be copied into the app bundle when built and used to define application behavior, for example it contains the url of the server this build should communicate with.</li>
<li>Build the app using the specified workspace and scheme. Copy the resulting app and dSYM to the project directory so TeamCity can easily find them as build artifacts.</li>
<li>Sign the app using the specified mobile provisioning profile and create a &#8220;.ipa&#8221; package.</li>
<li>Verify that the app was successfully signed.</li>
<li>Create a plist to allow over the air installation of the app.</li>
</ol>
<p>Once run any device which has been added to the mobile provisioning profile used to sign this build can install the app just by visiting (using an appropriate %system.teamcity.buildType.id% for the TeamCity build configuration).</p>
<blockquote><p>
itms-services://?action=download-manifest&amp;url=http://teamcity.example.com:8111/guestAuth/repository/download/%system.teamcity.buildType.id%/.lastSuccessful/project_name.acceptance.app.plist
</p></blockquote>
<p>Possible issues:</p>
<ul>
<li>Access to the keychain will present a security dialog the first time this build runs so it was necessary for me to sign into the TeamCity user&#8217;s account using VNC and allow access to that keychain.</li>
<li>I found that builds occasionally failed to correctly create the CodeResources symlink so I recreate it manually. When this link was broken the ipa would fail verification.</li>
<li>An iOS device won&#8217;t be able to install the app if the artifacts require authenticating to the TeamCity server so I enabled guest access. Alternately I could have exposed those artifacts through some other service and created a nice installation guide page which links to them if I didn&#8217;t want to allow guest access to my TeamCity server.</li>
</ul>
<p>For additional resources for building over the air distribution builds take a look at:</p>
<p>Mike Nachbaur&#8217;s posts on &#8220;<a href="http://nachbaur.com/blog/how-to-automate-your-iphone-app-builds-with-hudson">How to Automate your iPhone App Builds with Hudson</a>&#8221; and &#8220;<a href="http://nachbaur.com/blog/building-ios-apps-for-over-the-air-adhoc-distribution">Building iOS Apps for Over the Air Ad Hoc Distribution</a>&#8220;.<br />
Vincent Daubry&#8217;s &#8220;<a href="http://blog.octo.com/en/automating-over-the-air-deployment-for-iphone/">Automating Over The Air Deployment for iPhone</a>&#8220;.<br />
Basil Shkara&#8217;s &#8220;<a href="http://www.neat.io/posts/2010/10/27/automated-ota-ios-app-distribution.html">Automated OTA iOS App Distribution</a>&#8220;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2011/05/04/automated-ad-hoc-builds-using-xcode-4/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Running Xcode 4 unit tests from the command line</title>
		<link>http://blog.carbonfive.com/2011/04/06/running-xcode-4-unit-tests-from-the-command-line/</link>
		<comments>http://blog.carbonfive.com/2011/04/06/running-xcode-4-unit-tests-from-the-command-line/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 12:00:02 +0000</pubDate>
		<dc:creator>Jonah Williams</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=3351</guid>
		<description><![CDATA[Command line builds for Xcode 4 projects are a good first step but I really want to get my project&#8217;s tests running on a continuous integration server again. Since &#8220;test&#8221; isn&#8217;t a valid build action to pass to xcodebuild I&#8217;ve &#8230; <a href="http://blog.carbonfive.com/2011/04/06/running-xcode-4-unit-tests-from-the-command-line/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.carbonfive.com/2011/04/06/building-xcode-4-projects-from-the-command-line/">Command line builds for Xcode 4 projects</a> are a good first step but I really want to get my project&#8217;s tests running on a continuous integration server again. Since &#8220;test&#8221; isn&#8217;t a valid build action to pass to xcodebuild I&#8217;ve been looking for a configuration which would allow me to run tests in a headless environment.<br />
<span id="more-3351"></span><br />
I expect that GTM, GHUnit, and Cedar will all have reliable support for Xcode 4 projects eventually but I would like to start with just seeing some SenTestingKit tests pass.</p>
<p>I have been able to run test suites from the command line but only for &#8220;logic&#8221; tests. From the <a href="http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html">iOS Development Guide</a>:</p>
<blockquote><p>Xcode offers two types of unit tests: logic tests and application tests.</p>
<p>Logic tests.<br />
These tests check the correct functionality of your code in a clean-room environment; that is, your code is not run inside an application. Logic tests let you put together very specific test cases to exercise your code at a very granular level (a single method in class) or as part of a workflow (several methods in one or more classes). You can use logic tests to perform stress-testing of your code to ensure that it behaves correctly in extreme situations that are unlikely in a running application. These tests help you produce robust code that works correctly when used in ways that you did not anticipate. Logic tests are iOS Simulator SDK–based; however, the application is not run in iOS Simulator: The code being tested is run during the corresponding target’s build phase.</p>
<p>Application tests.<br />
These tests check the functionality of your code in a running application. You can use application tests to ensure that the connections of your user-interface controls (outlets and actions) remain in place, and that your controls and controller objects work correctly with your object model as you work on your application. Because application tests run only on a device, you can also use these tests to perform hardware testing, such as getting the location of the device.</p></blockquote>
<p>I am able to create a set of logic tests as a separate build target and scheme which will successfully run as part of an xcodebuild build.</p>
<ol>
<li>Create a new &#8220;LogicTests&#8221; unit test build target.</li>
<li>Leave the &#8220;Test Host&#8221; build setting blank.</li>
<li>Set the &#8220;Test After Build&#8221; build setting to &#8220;No&#8221;.</li>
<li>Do not write tests which require an application to be present (ie no window or application delegate available).</li>
<li>Create a new &#8220;LogicTests&#8221; scheme which includes the &#8220;LogicTests&#8221; build target in its run action.</li>
<li>Run the &#8220;LogicTests&#8221; scheme using xcodebuild.</li>
</ol>
<p><div id="attachment_3375" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/screen-shot-2011-04-05-at-11-51-39-pm.png"><img src="http://blog.carbonfive.com/wp-content/uploads/2011/04/screen-shot-2011-04-05-at-11-51-39-pm.png?w=300" alt="Scheme for running logic tests" title="logic_test_scheme" width="300" height="205" class="size-medium wp-image-3375" /></a><p class="wp-caption-text">Scheme for running logic tests</p></div></p>
<blockquote><p>&gt; /Developer_Xcode4/usr/bin/xcodebuild -workspace WrappingScrollView.xcworkspace -scheme logictests -sdk iphonesimulator4.3 -configuration Debug clean build</p>
<p>&#8230;</p>
<p>Run test suite logictests<br />
Test Suite &#8216;logictests&#8217; started at 2011-04-06 07:44:57 +0000<br />
Run test case testExample<br />
Test Case &#8216;-[logictests testExample]&#8216; started.<br />
/Users/Jonah/Desktop/WrappingScrollView/WrappingScrollViewDemo/logictests/logictests.m:30: error: -[logictests testExample] : Unit tests are not implemented yet in logictests<br />
Test Case &#8216;-[logictests testExample]&#8216; failed (0.000 seconds).</p>
<p>Test Suite &#8216;logictests&#8217; finished at 2011-04-06 07:44:57 +0000.<br />
Executed 1 test, with 1 failure (0 unexpected) in 0.000 (0.000) seconds
</p></blockquote>
<p>That&#8217;s not a great solution but it at least allows me to run some tests on a continuous integration server. Hopefully I can find a way to run application tests through xcodebuild as well.</p>
<p>In case it is of any help to other developers struggling with the difference between command line and Xcode builds. The &#8220;Run Script&#8221; build phase of a unit test build target just runs &#8220;${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests&#8221;. The RunUnitTests script in turn invokes a platform specific script like &#8220;${SYSTEM_DEVELOPER_DIR}/Platforms/iPhoneSimulator.platform/Developer/Tools/RunPlatformUnitTests&#8221;  which ultimately calls RunTestsForBundle in &#8220;${SYSTEM_DEVELOPER_DIR}/Tools/RunPlatformUnitTests.include&#8221;. Hopefully it will prove possible to use these scripts to match the behavior seen when running tests from within Xcode to automatically run application tests.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2011/04/06/running-xcode-4-unit-tests-from-the-command-line/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Building Xcode 4 projects from the command line</title>
		<link>http://blog.carbonfive.com/2011/04/06/building-xcode-4-projects-from-the-command-line/</link>
		<comments>http://blog.carbonfive.com/2011/04/06/building-xcode-4-projects-from-the-command-line/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 10:00:59 +0000</pubDate>
		<dc:creator>Jonah Williams</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=3336</guid>
		<description><![CDATA[The Xcode 4 developer tools introduced some changes to the xcodebuild command line tool. Instead of specifying a project and target developers can now provide a workspace and scheme to build. &#62; /Developer_Xcode4/usr/bin/xcodebuild -help Usage: xcodebuild [-project ] [[-target ]&#8230;&#124;-alltargets] &#8230; <a href="http://blog.carbonfive.com/2011/04/06/building-xcode-4-projects-from-the-command-line/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The Xcode 4 developer tools introduced some changes to the xcodebuild command line tool. Instead of specifying a project and target developers can now provide a workspace and scheme to build.<br />
<span id="more-3336"></span></p>
<blockquote><p>&gt; /Developer_Xcode4/usr/bin/xcodebuild -help<br />
Usage: xcodebuild [-project ] [[-target ]&#8230;|-alltargets] [-configuration ] [-arch ]&#8230; [-sdk [|]] [=]&#8230; []&#8230;<br />
       xcodebuild -workspace  -scheme  [-configuration ] [-arch ]&#8230; [-sdk [|]] [=]&#8230; []&#8230;<br />
       xcodebuild -version [-sdk [|] [] ]<br />
       xcodebuild -list [[-project ]|[-workspace ]]<br />
       xcodebuild -showsdks
</p></blockquote>
<p>The workspace and scheme names should be known from the project. The default configuration options are &#8220;Debug&#8221; and &#8220;Release&#8221;. The &#8220;-showsdks&#8221; option lists available SDKs.</p>
<blockquote><p>&gt; /Developer_Xcode4/usr/bin/xcodebuild -showsdks<br />
Mac OS X SDKs:<br />
	Mac OS X 10.6                 	-sdk macosx10.6</p>
<p>iOS SDKs:<br />
	iOS 4.3                       	-sdk iphoneos4.3</p>
<p>iOS Simulator SDKs:<br />
	Simulator &#8211; iOS 3.2           	-sdk iphonesimulator3.2<br />
	Simulator &#8211; iOS 4.0           	-sdk iphonesimulator4.0<br />
	Simulator &#8211; iOS 4.1           	-sdk iphonesimulator4.1<br />
	Simulator &#8211; iOS 4.2           	-sdk iphonesimulator4.2<br />
	Simulator &#8211; iOS 4.3           	-sdk iphonesimulator4.3
</p></blockquote>
<p>Available build actions are listed in the xcodebuild man pages. Unfortunately these do not match the actions available in a scheme and the command line does not provide a mechanism for testing, running, profiling, or analyzing builds.</p>
<blockquote><p>&gt; man xcodebuild<br />
&#8230;</p>
<p>buildaction &#8230;<br />
           Specify a build action (or actions) to perform on the target. Available build actions are:</p>
<p>           build       Build the target in the build root (SYMROOT).  This is the default build action.</p>
<p>           archive     Archive a scheme from the build root (SYMROOT).  This requires specifying a workspace and scheme.</p>
<p>           installsrc  Copy the source of the project to the source root (SRCROOT).</p>
<p>           install     Build the target and install it into the target&#8217;s installation directory in the distribution root (DSTROOT).</p>
<p>           clean       Remove build products and intermediate files from the build root (SYMROOT).
</p></blockquote>
<p>Given all of these configuration options it is then possible to perform builds from the command line.</p>
<blockquote><p>&gt; /Developer_Xcode4/usr/bin/xcodebuild -workspace WrappingScrollView.xcworkspace -scheme WrappingScrollViewDemo -sdk iphonesimulator4.3 -configuration Debug clean build<br />
Build settings from command line:<br />
    SDKROOT = iphonesimulator4.3</p>
<p>=== CLEAN NATIVE TARGET JCFWrappingScrollView OF PROJECT JCFWrappingScrollView WITH CONFIGURATION Debug ===<br />
Check dependencies</p>
<p>&#8230;</p>
<p>** CLEAN SUCCEEDED **</p>
<p>=== BUILD NATIVE TARGET JCFWrappingScrollView OF PROJECT JCFWrappingScrollView WITH CONFIGURATION Debug ===<br />
Check dependencies</p>
<p>ProcessPCH /Users/Jonah/Library/Developer/Xcode/DerivedData/WrappingScrollView-fqscqfdtpoqunuanehtbgpseirdj/Build/PrecompiledHeaders/JCFWrappingScrollView-Prefix-dkkjrdaonxokgpbkgjfmpmcpadoz/JCFWrappingScrollView-Prefix.pch.gch JCFWrappingScrollView/JCFWrappingScrollView-Prefix.pch normal i386 objective-c com.apple.compilers.llvmgcc42<br />
    cd /Users/Jonah/Desktop/WrappingScrollView/JCFWrappingScrollView<br />
    setenv LANG en_US.US-ASCII</p>
<p>&#8230;</p>
<p>** BUILD SUCCEEDED **
</p></blockquote>
<p>Hopefully that is sufficient to automatically produce ad-hoc builds on a continuous integration server.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2011/04/06/building-xcode-4-projects-from-the-command-line/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Using Open Source Static Libraries in Xcode 4</title>
		<link>http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/</link>
		<comments>http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 18:00:21 +0000</pubDate>
		<dc:creator>Jonah Williams</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=3196</guid>
		<description><![CDATA[Xcode 4.0.1 allows us to more easily create and use third party libraries in iOS projects. I think the process is still more complicated than it needs to be. Xcode&#8217;s documentation suggests that it should automatically detect implicit dependencies and &#8230; <a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Xcode 4.0.1 allows us to more easily create and use third party libraries in iOS projects. I think the process is still more complicated than it needs to be. Xcode&#8217;s documentation suggests that it should automatically detect implicit dependencies and index classes across workspaces but I have not found this to be the case. Here I&#8217;ll cover the steps I have found for creating and sharing code between projects and with other developers.<br />
<span id="more-3196"></span></p>
<ol>
<li><a href="#background">Background</a></li>
<li><a href="#using_a_static_library">Using a Static Library</a></li>
<li><a href="#creating_a_static_library">Creating a Static Library</a></li>
<li><a href="#future_improvements">Future Improvements</a></li>
</ol>
<p><a name="background"></a></p>
<h2>Background</h2>
<h3>Workspaces:</h3>
<p>Xcode 4 introduced the concept of <a href="http://developer.apple.com/library/ios/#featuredarticles/XcodeConcepts/Concept-Workspace.html">workspaces</a> as containers for multiple projects. There are a couple of key behaviors of workspaces which we want to build on when choosing how to share code across projects.</p>
<ul>
<li>By default, all the Xcode projects in a workspace are built in the same directory, referred to as the workspace build directory.</li>
<li>Xcode examines the files in the build directory to discover implicit dependencies.</li>
<li>Each project in a workspace continues to have its own independent identity.</li>
</ul>
<h3>Schemes:</h3>
<p>Within a workspace or within a project which is a member of a workspace we have <a href="http://developer.apple.com/library/ios/#featuredarticles/XcodeConcepts/Concept-Schemes.html">schemes</a>. Schemes replace the Active Target, Build Configuration, and Executable settings from Xcode 3 and define which targets to build, the order in which to build them, and what action to take when a build is complete. We&#8217;ll want our shared code to easily fit into the scheme of any projects which use it. The <a href="http://developer.apple.com/library/mac/#documentation/IDEs/Conceptual/Xcode4TransitionGuide/Orientation/Orientation.html#//apple_ref/doc/uid/TP40009984-CH5-SW26">Xcode 4 Transition Guide</a> covers this new structure in more detail.</p>
<h3>Targets:</h3>
<p>Within a scheme we have one or more build <a href="http://developer.apple.com/library/ios/#featuredarticles/XcodeConcepts/Concept-Targets.html">targets</a> which define a set of source files to build, the settings used to build those files, and any dependencies on the build products of other targets which must be completed first. Ultimately we would like a consumer of our code to be able to state that their project&#8217;s build target depends on our shared code and have Xcode build this shared code and make it available to the active build target. We can achieve that by providing a project containing the code to be shared and a static library build target which packages it into a build product other developers can add as a build target dependency.<br />
<a name="using_a_static_library"></a></p>
<h2>Using a static library</h2>
<ol>
<li><a href="#creating_a_workspace">Creating a workspace</a></li>
<li><a href="#adding_projects_to_a_workspace">Adding projects to a workspace</a></li>
<li><a href="#adding_build_target_dependencies">Adding build target dependencies</a></li>
<li><a href="#adding_the_static_librarys_headers">Adding the static library&#8217;s headers</a></li>
<li><a href="#configuring_the_projects_scheme">Configuring the project&#8217;s scheme</a></li>
<li><a href="#fixing_indexing">Fixing indexing</a></li>
</ol>
<p><a name="creating_a_workspace"></a></p>
<h3>Creating a workspace</h3>
<p>We can create a new empty workspace from Xcode&#8217;s file menu or open an existing project and select &#8220;Save As Workspace&#8230;&#8221; to create a new workspace containing our project. This will create a &#8220;.xcworkspace&#8221; package in the file system.</p>
<p><div id="attachment_3314" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/empty_workspace.png"><img class="size-medium wp-image-3314" title="empty workspace" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/empty_workspace.png?w=300" alt="An empty Xcode 4 workspace" width="300" height="147" /></a><p class="wp-caption-text">An empty Xcode 4 workspace</p></div><br />
<a name="adding_projects_to_a_workspace"></a></p>
<h3>Adding projects to a workspace</h3>
<p>Once we have a workspace we can right-click in the workspace&#8217;s navigator to create a new project or add an existing &#8220;.xcodeproj&#8221; package.</p>
<p><div id="attachment_3317" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/adding_a_project.png"><img class="size-medium wp-image-3317" title="adding a project" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/adding_a_project.png?w=300" alt="Adding a new project to a workspace" width="300" height="184" /></a><p class="wp-caption-text">Adding a new project to a workspace</p></div></p>
<p><div id="attachment_3318" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/adding_an_existing_project.png"><img class="size-medium wp-image-3318" title="adding an existing project" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/adding_an_existing_project.png?w=300" alt="Adding an existing project to a workspace" width="300" height="274" /></a><p class="wp-caption-text">Adding an existing project to a workspace</p></div></p>
<p>We want to end up with a single workspace containing our app&#8217;s project and the projects for any static libraries we are going to depend on. It is worth noting that these projects are all siblings in the workspace, our static libraries are not added as references within our app&#8217;s project.</p>
<p>&nbsp;<br />
<a name="adding_build_target_dependencies"></a></p>
<h3>Adding build target dependencies</h3>
<p>With all of the projects we need available in our workspace we can select our app&#8217;s build target and add a static library to the &#8220;Link Binary With Libraries&#8221; build phase.</p>
<p><div id="attachment_3319" class="wp-caption alignnone" style="width: 224px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/linkable_libraries.png"><img class="size-medium wp-image-3319" title="linkable libraries" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/linkable_libraries.png?w=214" alt="Libraries and frameworks available to add to the &quot;Link Binary With Libraries&quot; build phase" width="214" height="300" /></a><p class="wp-caption-text">Libraries and frameworks available to add to the &quot;Link Binary With Libraries&quot; build phase</p></div></p>
<p><div id="attachment_3320" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/linking_with_static_library.png"><img class="size-medium wp-image-3320" title="linking with a static library" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/linking_with_static_library.png?w=300" alt="A static library added to the &quot;Link Binary With Libraries&quot; build phase" width="300" height="170" /></a><p class="wp-caption-text">A static library added to the &quot;Link Binary With Libraries&quot; build phase</p></div><br />
<a name="adding_the_static_librarys_headers"></a></p>
<h3>Adding the static library&#8217;s headers</h3>
<p>We also need to make sure that our app&#8217;s build target can locate the public headers used in this static library. Open the &#8220;Build Settings&#8221; tab and locate the &#8220;User Header Search Paths&#8221; setting. Set this to &#8220;$(BUILT_PRODUCTS_DIR)&#8221; (or &#8220;$(BUILT_PRODUCTS_DIR)/static_library_name&#8221; if we want to be more specific but then we&#8217;ll have to update this setting every time we add another library) and check the &#8220;Recursive&#8221; check box. Now our built target will search our workspace&#8217;s shared build directory to locate linkable header files.</p>
<p><div id="attachment_3321" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/header_search_path_value.png"><img class="size-medium wp-image-3321" title="user header search paths value" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/header_search_path_value.png?w=300" alt="Setting the User Header Search Paths" width="300" height="194" /></a><p class="wp-caption-text">Setting the User Header Search Paths</p></div></p>
<p><div id="attachment_3322" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/set_user_header_search_paths.png"><img class="size-medium wp-image-3322" title="user header search paths set" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/set_user_header_search_paths.png?w=300" alt="User Header Search Paths set" width="300" height="147" /></a><p class="wp-caption-text">User Header Search Paths set</p></div></p>
<p>The &#8220;User Header Search Paths&#8221; setting defines the headers available as quoted imports (eg &#8220;#import &#8220;MyLibraryClass.h&#8221;) while the &#8220;Header Search Paths&#8221; setting defines those headers available as bracketed imports (eg &#8220;#import ). I&#8217;ve found that Xcode will only autocomplete header names in the quoted form so I always add libraries to the user header search path even though, from my project&#8217;s perspective, they might be more appropriate as system level (angle bracketed) libraries.</p>
<p>When using a static library which includes categories we will also have to add the &#8220;-ObjC&#8221; flag to the &#8220;Other Linker Flags&#8221; build setting. This will force the linker to load all objective-c classes and categories from the library. If the library contains only categories &#8220;-all_load&#8221; or &#8220;-force_load&#8221; may be needed as well. See <a href="http://developer.apple.com/library/mac/#qa/qa1490/_index.html">Technical Q&amp;A QA1490</a> for a more detailed explanation of these settings.<br />
<a name="configuring_the_projects_scheme"></a></p>
<h3>Configuring the project&#8217;s scheme</h3>
<p>At this point Xcode should have detected this implicit dependency between our app&#8217;s project and the static library&#8217;s project and have automatically configured our schemes correctly. Unfortunately I haven&#8217;t found this to be the case in practice. Instead we will have to edit our current scheme and add the static library&#8217;s build target before our app&#8217;s build target.</p>
<p><div id="attachment_3323" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/setting_target_build_order.png"><img class="size-medium wp-image-3323" title="setting target build order" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/setting_target_build_order.png?w=300" alt="Setting the scheme's target build order" width="300" height="205" /></a><p class="wp-caption-text">Setting the scheme&#039;s target build order</p></div><br />
<a name="fixing_indexing"></a></p>
<h3>Fixing indexing</h3>
<p>At this point we should be able to include headers from dependent static libraries, use the included classes, and still successfully build our app. Unfortunately Xcode will not show any classes from these linked static libraries in code completion despite the workspace documentation stating that &#8220;indexing is done across the entire workspace, extending the scope of content-aware features such as code completion and refactoring.&#8221;<br />
As a workaround we can drag the public headers from the static library&#8217;s project into our app&#8217;s project, adding them as references. These headers do not need to be included in any of our build targets, simply having references to the headers in our project will allow their classes to appear in code completion.<br />
<a name="creating_a_static_library"></a></p>
<h2>Creating a Static Library</h2>
<p>If we plan on releasing some of our own code for reuse as a static library there are several things we should do to make sure that the process described above is as easy and simple as possible for our library&#8217;s users.</p>
<ol>
<li><a href="#namespace_classes_appropriately">Namespace classes appropriately</a></li>
<li><a href="#create_a_build_target">Create a build target</a></li>
<li><a href="#expose_public_headers">Expose public headers</a></li>
<li><a href="#set_the_installation_directory">Set the installation directory</a></li>
<li><a href="#set_the_public_header_path">Set the public header path</a></li>
<li><a href="#exclude_user_specific_files_from_vcs">Exclude user specific files from VCS</a></li>
</ol>
<p><a name="namespace_classes_appropriately"></a></p>
<h3>Namespace classes appropriately</h3>
<p>Use an appropriate <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingBasics.html#//apple_ref/doc/uid/20001281-1002226">prefix</a> for classes, protocols, functions, and constants in the library to prevent collisions with names in the library&#8217;s user&#8217;s project.<br />
<a name="create_a_build_target"></a></p>
<h3>Create a build target</h3>
<p>Provide a static library build target in the project for our users to link against. Xcode provides templates for creating projects with static libraries or adding static library build targets to existing projects.<br />
<a name="expose_public_headers"></a></p>
<h3>Expose public headers</h3>
<p>Determine which header files should be visible to users of the library. Provide a clearly named group containing these headers so that our library&#8217;s users can easily locate them as part of the workaround described in &#8220;Fixing Indexing&#8221; above. This also helps us clarify what the public interface our library provides is and what classes are implementation details which are likely to change as the library evolves.</p>
<p>For each public header file make sure it is set as &#8220;public&#8221; in the &#8220;Target Membership&#8221; section of the inspector pane. Only public headers are going to be available for our users to import.</p>
<p><div id="attachment_3326" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/making_headers_public.png"><img class="size-medium wp-image-3326" title="making headers public" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/making_headers_public.png?w=300" alt="Making a header file public" width="300" height="147" /></a><p class="wp-caption-text">Making a header file public</p></div><br />
<a name="set_the_installation_directory"></a></p>
<h3>Set installation directory</h3>
<p>Our static library build target is going to be a member of a user&#8217;s workspace and subject to that workspace&#8217;s installation rules. Our static library build product could therefore be installed in a location set by Xcode&#8217;s preferences, in the derived data path, or in a path specified by our build target. Since we can&#8217;t control the user&#8217;s settings we should make sure our library is well behaved in all cases. I set the &#8220;Installation Directory&#8221; build setting to &#8220;$(BUILT_PRODUCTS_DIR)&#8221; so that the static library build product can be found in a known location and set the &#8220;Skip Install&#8221; build setting to &#8220;Yes&#8221; to avoid accidentally installing iOS libraries into &#8220;/usr/local/lib&#8221;.</p>
<p><div id="attachment_3327" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/set_installation_directory.png"><img class="size-medium wp-image-3327" title="set installation directory" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/set_installation_directory.png?w=300" alt="Setting the installation directory" width="300" height="164" /></a><p class="wp-caption-text">Setting the installation directory</p></div><br />
<a name="set_the_public_header_path"></a></p>
<h3>Set the public header path</h3>
<p>We need to specify a location to copy our static library&#8217;s public headers to so that they can be included in our users&#8217; header search paths. Setting the &#8220;Public Headers Folder Path&#8221; to &#8220;$(TARGET_NAME)&#8221; will create a folder named after our static library build target in the workspace&#8217;s shared build directory and be indexed by the &#8220;User Header Search Paths&#8221; setting described above.</p>
<p><div id="attachment_3328" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/set_public_headers_path.png"><img class="size-medium wp-image-3328" title="set public headers path" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/set_public_headers_path.png?w=300" alt="Setting the public headers path for the static library" width="300" height="147" /></a><p class="wp-caption-text">Setting the public headers path for the static library</p></div><br />
<a name="exclude_user_specific_files_from_vcs"></a></p>
<h3>Exclude user specific files from VCS</h3>
<p>Our workspace and project include a number of files which contain data relevant only to our user account; window positions, open files, and so on. There&#8217;s no need to check these into source control, at least not in our release branch, so let&#8217;s set some reasonable ignore rules in git or whatever VCS we are using. Github provides a convenient set of <a href="https://github.com/github/gitignore">.gitignore files</a><br />
<a name="future_improvements"></a></p>
<h2>Future Improvements</h2>
<p>Hopefully Xcode 4 will eventually live up to the promise of it&#8217;s documentation and consistently auto-detect implicit dependencies and index files across the workspace correctly. There certainly seem to be a number of other developers struggling with this behavior:[<a href="https://devforums.apple.com/message/390470#390470">1</a>], [<a href="https://devforums.apple.com/message/399673#399673">2</a>], [<a href="https://devforums.apple.com/message/397932#397932">3</a>], [<a href="https://devforums.apple.com/message/399316#399316">4</a>], [<a href="https://devforums.apple.com/message/375741#375741">5</a>], [<a href="https://devforums.apple.com/message/377781#377781">6</a>], [<a href="http://stackoverflow.com/questions/5427396/whats-the-correct-way-to-configure-xcode-4-workspaces-to-build-dependencies-when">7</a>], [<a href="http://stackoverflow.com/questions/5483909/how-should-i-manage-dependencies-across-projects-in-an-xcode-workspace">8</a>]. Until that indexing improves I find that this process is at least somewhat simpler and cleaner than trying to maintain simulator and device compatible static library builds in Xcode 3.<br />
I&#8217;ve found this pattern preferable to copying third party classes directly into my projects as it allows me to easily keep version history and make updates to static library projects in my workspace and avoids coupling my project too closely to the private structure and contents of the static library.<br />
Please let me know if you can see any areas where this pattern could be improved or if you&#8217;ve found your own alternative means of sharing code.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/feed/</wfw:commentRss>
		<slash:comments>55</slash:comments>
		</item>
		<item>
		<title>Code Formatting in Xcode 4</title>
		<link>http://blog.carbonfive.com/2011/03/10/code-formatting-in-xcode-4/</link>
		<comments>http://blog.carbonfive.com/2011/03/10/code-formatting-in-xcode-4/#comments</comments>
		<pubDate>Thu, 10 Mar 2011 10:19:25 +0000</pubDate>
		<dc:creator>Jonah Williams</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=3035</guid>
		<description><![CDATA[Automatic indentation and cleanup of code seems to have improved in Xcode 4 (Editor menu &#8211; Structure &#8211; Re-Indent) but it still doesn&#8217;t offer full code reformatting or the flexibility of a tool like Uncrustify. If you&#8217;re used to having &#8230; <a href="http://blog.carbonfive.com/2011/03/10/code-formatting-in-xcode-4/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Automatic indentation and cleanup of code seems to have improved in Xcode 4 (Editor menu &#8211; Structure &#8211; Re-Indent) but it still doesn&#8217;t offer full code reformatting or the flexibility of a tool like Uncrustify. If you&#8217;re used to having external <a href="http://blog.carbonfive.com/2009/08/07/code-formatting-in-xcode/">code formatting in Xcode</a> available you might be disappointed to find the User Scripts menu missing in Xcode 4. </p>
<p>Thankfully <a href="https://github.com/tonyarnold">Tony Arnold</a> demonstrated one possible solution with his <a href="https://github.com/tonyarnold/Xcode-4-Uncrustify-Automator-Services">Xcode 4 Uncrustify Automator Services</a>. Here&#8217;s how you can get your external code formatting tool up and running again with Xcode 4.<br />
<span id="more-3035"></span><br />
Install Uncrustify (<code>port install uncrustify</code>, <code>brew install uncrustify</code>, or directly from <a href="http://uncrustify.sourceforge.net/">http://uncrustify.sourceforge.net/</a>)</p>
<p>Open Automator and create a new Service.<br />
<div id="attachment_3092" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/03/create_service_in_automator.png"><img src="http://blog.carbonfive.com/wp-content/uploads/2011/03/create_service_in_automator.png?w=300" alt="Creating a Service in Automator" title="create_service_in_automator" width="300" height="278" class="size-medium wp-image-3092" /></a><p class="wp-caption-text">Creating a new Automator Service</p></div></p>
<p>Inputs to Automator Services are more limited than the options available in Xcode 3&#8242;s User Scripts. To reformat selected text we can still pass the input from Xcode to a Run Shell Script action.</p>
<pre class="brush: bash; title: ; notranslate">uncrustify -l OC -q -c ~/.uncrustify/uncrustify_obj_c.cfg</pre>
<p><div id="attachment_3093" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/03/uncrustify_selected_text.png"><img src="http://blog.carbonfive.com/wp-content/uploads/2011/03/uncrustify_selected_text.png?w=300" alt="The &quot;uncrustify selected text&quot; service in Automator" title="uncrustify_selected_text" width="300" height="186" class="size-medium wp-image-3093" /></a><p class="wp-caption-text">Uncrustify Selected Text</p></div></p>
<p>To reformat open files we need to use AppleScript to get the paths to those files so that we can pass them to Uncrustify. I wasn&#8217;t able to find a reliable way to select only the currently visible source file so I settled on the following script to reformat all open and modified source files instead. </p>
<pre class="brush: objc; title: ; notranslate">
tell application id &amp;quot;com.apple.dt.Xcode&amp;quot;
	repeat with current_document in (source documents whose modified is true)
		set current_document_path to path of current_document
		set raw_source to text of current_document
		set formatted_source to do shell script &amp;quot;uncrustify -l OC -q -c ~/.uncrustify/uncrustify_obj_c.cfg -f &amp;quot; &amp;amp; current_document_path
		set text of current_document to formatted_source
	end repeat
end tell
</pre>
<p><div id="attachment_3094" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/03/uncrustify_modified_documents.png"><img src="http://blog.carbonfive.com/wp-content/uploads/2011/03/uncrustify_modified_documents.png?w=300" alt="The &quot;uncrustify modified documents&quot; service in Automator" title="uncrustify_modified_documents" width="300" height="222" class="size-medium wp-image-3094" /></a><p class="wp-caption-text">Uncrustify Modified Documents</p></div></p>
<p>Open Xcode, find the new Services available in the &#8220;Xcode&#8221; menu. Use the Services Preferences to bind these Services to keyboard shortcuts to your liking.<br />
<div id="attachment_3095" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/03/services_menu.png"><img src="http://blog.carbonfive.com/wp-content/uploads/2011/03/services_menu.png?w=300" alt="The Xcode and Services menus" title="services_menu" width="300" height="159" class="size-medium wp-image-3095" /></a><p class="wp-caption-text">Services available in Xcode</p></div></p>
<p>Enjoy cleaner code.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2011/03/10/code-formatting-in-xcode-4/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Continuous integration for iPhone projects in TeamCity</title>
		<link>http://blog.carbonfive.com/2010/08/08/continuous-integration-for-iphone-projects-in-teamcity/</link>
		<comments>http://blog.carbonfive.com/2010/08/08/continuous-integration-for-iphone-projects-in-teamcity/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 22:58:32 +0000</pubDate>
		<dc:creator>Jonah Williams</dc:creator>
				<category><![CDATA[Mobile]]></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 &#8230; <a href="http://blog.carbonfive.com/2010/08/08/continuous-integration-for-iphone-projects-in-teamcity/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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 =&gt; ExampleProject.zip</td>
</tr>
<tr>
<td>/Users/teamcity/xcode_builds/Distribution-iphoneos/ExampleProject.app.dSYM =&gt; 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/08/continuous-integration-for-iphone-projects-in-teamcity/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Multiple Environments in an iPhone Project</title>
		<link>http://blog.carbonfive.com/2010/02/12/multiple-environments-in-an-iphone-project/</link>
		<comments>http://blog.carbonfive.com/2010/02/12/multiple-environments-in-an-iphone-project/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 03:02:31 +0000</pubDate>
		<dc:creator>Jonah Williams</dc:creator>
				<category><![CDATA[Mobile]]></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 &#8230; <a href="http://blog.carbonfive.com/2010/02/12/multiple-environments-in-an-iphone-project/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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>
<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/12/screen-shot-2010-02-12-at-6-17-12-pm21.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>
<p>These plists should not be members of any build target (just like the original Info.plist.</p>
<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/12/screen-shot-2010-02-12-at-6-17-47-pm121.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>
<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>
<p><div id="attachment_836" class="wp-caption alignnone" style="width: 286px"><a href="http://blog.carbonfive.com/wp-content/uploads/2010/12/screen-shot-2010-02-12-at-6-18-52-pm21.png"><img class="size-full wp-image-836   " title="built_target_plist_settings" src="http://blog.carbonfive.com/wp-content/uploads/2010/12/screen-shot-2010-02-12-at-6-18-52-pm21.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>
<p>In code I can then access the plist&#8217;s dictionary via the application bundle:</p>
<pre class="brush: objc; light: true; title: ; wrap-lines: false; notranslate">[[NSBundle mainBundle] infoDictionary]
</pre>
<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/12/multiple-environments-in-an-iphone-project/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code Formatting in Xcode</title>
		<link>http://blog.carbonfive.com/2009/08/07/code-formatting-in-xcode/</link>
		<comments>http://blog.carbonfive.com/2009/08/07/code-formatting-in-xcode/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 23:37:39 +0000</pubDate>
		<dc:creator>Jonah Williams</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=658</guid>
		<description><![CDATA[Using Xcode 4? Take a look at Code Formatting in Xcode 4 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 &#8230; <a href="http://blog.carbonfive.com/2009/08/07/code-formatting-in-xcode/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Using Xcode 4? Take a look at <a href="http://blog.carbonfive.com/2011/03/10/code-formatting-in-xcode-4/">Code Formatting in Xcode 4</a></p>
<hr />
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>
<p><div id="attachment_660" class="wp-caption alignnone" style="width: 510px"><a href="http://blog.carbonfive.com/wp-content/uploads/2010/12/uncrustify-scripts21.png"><img class="size-full wp-image-660" title="uncrustify-scripts" src="http://blog.carbonfive.com/wp-content/uploads/2010/12/uncrustify-scripts21.png" alt="Uncrustify custom scripts in Xcode" width="500" height="332" /></a><p class="wp-caption-text">Uncrustify custom scripts in Xcode</p></div></p>
<pre class="brush: bash; light: true; title: ; wrap-lines: false; notranslate">#!/bin/sh

~/Applications/UniversalIndentGUI/indenters/uncrustify -l OC -q -c ~/Applications/UniversalIndentGUI/config/uncrustify_obj_c.cfg</pre>
<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>
<p>&nbsp;</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>
<hr />
<p>My config file is now also available as a gist: <a href="https://gist.github.com/841452">https://gist.github.com/841452</a> for anyone who would like to suggest improvements or create their own fork.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2009/08/07/code-formatting-in-xcode/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

