Few hands on tricks about -destination option of xcodebuild.
Destination option (-destination) was a new addition to Xcode 5 release. It is documented on xcodebuild man page and you get the same by running man xcodebuild. This option lets you be more verbose with your xcodebuild commands. For example, if you have a physical device plugged in, running xcodebuild with no destination specifier will build the project for this physical device. Using destination specifier you can explicitly tell xcodebuild to build for simulator.
Allow me just to quote the man page here
By the way, pay a closer attention to the last sentence. It’s a really nice feature, for example with single command you can run tests on multiple simulators.
One of the keys supported is “platform” and there are 3 options: “OS X”, “iOS” and “iOS Simulator”. Let’s get more details on the last two. iOS and iOS Simulator platforms both require a “name” and “OS” keys to specify device name and iOS version. The question is “How to get list of all names and OS versions?”. There are many ways to do that.
The Xcode Instruments command line utility has an undocumented -s option, which lists all devices and templates. By adding devices to the invocation only devices are be listed.
Example output, note that it also includes your Mac as a device.
Another option is to use xcrun simctl, which is a new addition to Xcode 6. In fact, simctl looks like a very promising tool that allows you to create, boot, launch and then shutdown and destroy iOS simulators on the fly, and provides commands to install and launch specific apps. If you ever used Genymotion you might have created Android simulators using VirtualBox command line utility, Apple works towards the same flexibility with simctl.
In context of this article, to see a list of available devices, run this command
You will get the list of device types, runtimes and devices. Device types and runtimes will be handy if you need to create new simulators. You can tell simctl to filter output, for example, list devices only
To get more details just run xcrun simctl list -h to get help on list command.
Finally, to get the most detailed output, ask xcodebuild itself. It is not really documented and doesn’t look like a proper approach, but it works. The idea is to give xcodebuild invalid key-value pair in destination specifier and wait until it complains about it offering a list of valid options in return.
The output is
Thanks Tor Arne for pointing out -destination-timeout option in the comments. Without this option xcodebuild will take way too long to figure out that destination doesn’t exist.
Back to Destination
Now that last output from xcodebuild is much better than anything else. It gives you all the key-value pairs as is, no additional guesswork involved. You get the “platform”, “OS” and “name” keys, and as a bonus you get an undocumented “id” key. Give it a try and see that it actually works.
You can adopt this approach as part of CI workflow automation and grep all key-value pairs from xcodebuild output.