<project name="my-iPhone-project">
<property name="xcodebuild" value="path_to_xcodebuilder_execuitable"/>
<property name="sdk" value="5.1"/>
<property name="build_path" value="/myhomepath/my_builds_folder"/>
<property name="application_path" value="${build_path}/Applications/my_iOS_application.app/my_application" />
<property name="simulator_path" value="/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator" />
<target name="run" depends="install, simulator"/>
<target name="build" depends="clean, make"/>
<target name="clean">
<delete dir="build" failonerror="false"/>
<xcodebuild target="my_application_target">
<arg value="clean"/>
</xcodebuild>
</target>
<target name="make">
<xcodebuild target="my_application_target">
<arg value="build"/>
</xcodebuild>
</target>
<target name="install" depends="build">
<xcodebuild target="my_application_target">
<arg value="install"/>
</xcodebuild>
</target>
<target name="simulator">
<iphone_simulator/>
</target>
<macrodef name="xcodebuild">
<attribute name="dir" default="/myhomepath/my_application_source_code_folder"/>
<attribute name="builddir" default="${build_path}"/>
<attribute name="failonerror" default="true"/>
<attribute name="target"/>
<attribute name="sdk" default="${sdk}"/>
<attribute name="configuration" default="${configuration}"/>
<element name="args" optional="true" implicit="true" />
<sequential>
<exec executable="${xcodebuild}" dir="@{dir}" failonerror="@{failonerror}" failifexecutionfails="@{failonerror}">
<arg value="-target"/>
<arg value="@{target}"/>
<arg value="-sdk"/>
<arg value="@{sdk}"/>
<arg value="-configuration"/>
<arg value="@{configuration}"/>
<arg value="SYMROOT=@{builddir}"/>
<arg value="DSTROOT=@{builddir}"/>
<args/>
</exec>
</sequential>
</macrodef>
<macrodef name="iphone_simulator">
<attribute name="applicationpath" default="${application_path}"/>
<sequential>
<exec executable="${simulator_path}" spawn="true">
<arg value="-SimulateApplication"/>
<arg value="@{applicationpath}"/>
<arg value="&"/>
</exec>
</sequential>
</macrodef>
</project>
What you should see when you save this build file and run Ant is xcodebuilder will start to clean, build and install our application, and when xcodebuilder will finish the iPhone simulater will start automatically to run our application.
Some key points here are the following:
- The xcodebuild property is the path to the xcodebuilder executable.
- The sdk property should be the iOS version you want to run your application.
- The build_path property is the path where xcodebuilder will build and install the application. It could be any path. Notice that this property is passed into the macro responsible of the xcodebuilder execution.
- The application_path property is the path of the application inside the build path. It should be similar to the example above because xcodebuilder installs the applications on folder called Applications.
- The simulator_path property is the path of the simulator executable.
- You should specify the target of the application by the attribute target in all the xcodebuilder calls. Don't confuse the application target with the Ant targets.
- The macro xcodebuild contains the necessary code to call the xcodebuilder executable. Pay attention to the first attribute dir, it is the path to the source code of your application. Your can use the same attributes and arguments as in the example, but it is advisable to check man page of xcodebuilder for a better understanding of the meaning of each available arguments. Be careful with the order of the arguments inside the sequential Ant container because it executes the nested tasks in sequence, so if you wrongly modify the order of the arguments, xcodebuild will not run.
- Finally the iphone_simulator macro will run the simulator starting your application. The last argument (the ampersand) is passed with the only purpose of execute the simulator in background.
This build file can be used in various ways but the most useful could be the launch of automated tests.



