Along with the release of iOS 7 for its mobile devices, Apple also introduced a major upgrade to its Xcode suite of development tools. Xcode, now in Version 5, consists of a compiler, a linker, a source-code-level debugger, a code analyzer, performance measurement instruments, a simulator, and other utilities, all managed by an IDE. The improvements in the Xcode 5 release should allow you to write better applications for iOS and OS X that are faster and have fewer bugs.
What in Xcode was changed to achieve these goals? Looking at the UI, you can see some minor tweaks (such as a smaller toolbar to give more screen real estate to the editor), but these modifications aren't as radical as the UI makeover Xcode saw with the Version 4 release. The major changes in Xcode 5 were made under the hood.
Building it faster
Before diving into the details, it's worth noting that the last vestiges of the GNU toolset, such as the GNU Compiler Collection and linker, have been swept away. Going forward, the only way to write and debug code for iOS or OS X is with Apple's LLVM compiler and LLDB debugger.
In addition, for OS X apps Garbage Collection (GC) is deprecated. You should use Automatic Reference Counting (ARC), a memory management scheme already in use on iOS. ARC produces more predictable patterns of code execution and memory use. In fact, Xcode itself was formerly a GC app, but with this release, it now uses ARC. The result is that many common Xcode operations, such as search, nib files compilation, and incremental builds are now twice as fast as in Xcode 4.
The IDE uses a new modules mechanism to accelerate code compilation and linking. Modules are similar to precompiled header files in that the plethora of API calls, class properties, and constants found in the lengthy header files are distilled down to symbolic references and information. However, in Xcode 5 this information is stored in an optimized and searchable symbols database. Now when the compiler encounters a symbolic reference, it can do a highly efficient database search for just the information required.
This is all done transparently; you don't have to change any of your code. With modules, Apple has seen improvements in build times that range from a few percent up to 40 percent faster, depending upon how well you managed your program's precompiled headers. Unfortunately, module support isn't available for C++ programs or private frameworks.
The compiler can parse comments made in Doxygen or HeaderDoc about method parameters and integrate this information into the documentation system. Xcode can even compare the function arguments in the code versus those in the comments and flag mismatches in the parameter names for you. This lets you fix both the code and the documentation as they evolve.
One time-consuming phase of app development is getting the UI to look right, especially for the different screen sizes of iOS devices. You can arrange UI elements with Interface Builder (IB), and set various constraints on where the elements land. Or you can allow IB to automatically place elements, but its results have been less than stellar.
For Xcode 5, the auto layout mechanism has been much improved. IB now lets you more accurately specify how elements can be constrained (say, several buttons must remain in a line) and how they are free to move about (these buttons are free to move up and down the screen's vertical axis). Apple emphasizes that you should use auto layout going forward, which is a big hint that devices with different screen sizes are forthcoming.
Making it faster
The compiler's code generator has been tuned to emit optimized ARMv7s instructions for iOS apps. Using these optimized instructions, Apple has seen a boost in execution speed of apps ranging from 15 to 30 percent. The LLVM compiler also better supports SIMD (single instruction, multiple data) instructions such as ARM's NEON and Intel's AVX2, which is in Intel's new Haswell CPU. The SIMD support enables the compiler to implement an autovectorizer, an optimization technique that translates certain compute-intensive loops into SIMD instruction sequences that operate on multiple chunks of data (instead of one) with each loop iteration. Depending upon the code, Apple saw performance boosts ranging from 1.5x to 7.9x.
The compiler also generates 64-bit instructions that improve computational performance, especially when used on the 64-bit A7 CPU in the iPhone 5s. The 64-bit tool support is also necessary to build iOS 7, which is now a 64-bit OS. Taken together, the CPU, OS, and tools should enable a new category of applications that use complex algorithms to manipulate large data sets.
C++ programmers, Apple has not forgotten you. Continuing its steady addition of C++ v11 language features to the tools, Apple has included support for user-defined literals, generalized attributes, inheriting constructors, alignment declarations, and unrestricted unions with this release. This brings Xcode 5 into almost full compliance with the C++ v11 standard. Note that Apple's LLVM C++ standard library is required to access the latest C++ v11 features and all-new Cocoa frameworks.
More productive programming
Faster code, if not written properly, simply crashes faster. The Xcode 5 debugger has improvements that should make it easier to find bugs in your code. The debugger has a data tips feature that displays the contents of that variable when you hover the pointer over a variable name. If the variable is a complex structure, the data tip unravels it to display the individual elements in the structure. You can then use the data tip to explore the values of the elements.
The data tips feature is not new, but new to Xcode 5 is how this feature now extends to graphic data: If the item is a view that contains a rectangle, a Bezier curve, or a pixel image, the graphic is displayed. This combination data/graphic display lets you confirm that all elements have the values (or graphics) that you expect. If not, it's time to investigate why.
The debugger now has lightweight real-time gauges that display specific attributes of the app's operation, such as CPU and memory usage, as it executes. Gauges for iCloud connections, energy consumption, and OpenGL ES operations are also built in to the IDE. These gauges consume less than 1 percent in overhead so as not to affect the app's behavior.
As your program runs, the gauges appear as simple moving bar graphs that can make a sudden spike in CPU cycles or a slow memory leak evident at a glance. Clicking on the bar graph generates a more detailed report such as current CPU and peak CPU usage. If the problem is not apparent, you can click on a button that brings in the heavy artillery -- the Instruments utilities -- for a deep and detailed (and more invasive) examination as the program continues to run. Gauges are also good at helping you fine-tune your app's performance and minimize its CPU usage and battery consumption.
Hardening the code
Xcode 5 provides better support for source code control and unit tests. This allows you to manage your code and harden it against edge cases or bugs that attempt to creep in as features are added. To achieve this, Xcode 5 has better integration with source control systems. You can easily log into a source control repository from the Xcode editor and use source control commands such as check out, commit, update, and discard. The editor can also display information such as who made a change in a specific line of code. Furthermore, you can check out source branches, create new ones, and commit them. This helps you keep track of changes in the code and makes coding errors easier to trace.
For unit test operations, a new Test Navigator lets you point and click to select the tests you want to run. After the suite of tests completes, you get a status report on which of them passed and which failed. Clicking on a test report takes you to the program's source code, where you can -- courtesy of the source control system -- drill down with the editor to specific lines of code.
You can now make bots that automate a sequence of app builds, test runs, code signing, and archiving operations. A bot is simply an agent that resides on an OS X Server instance, which can be the same Mac that is running Xcode. The bot manages the builds of the specified apps and executes tests on various Apple devices. When done, the bot then generates a results report. Bots are good for performing continuous regression tests or nightly builds. Because bots run on the server, they are out of the way, and the server is a good place to share test devices. The server also functions as a repository for various builds and error logs. No rocket science is required to set up a bot -- a wizard in Xcode 5 guides you through configuring one. A bot requires that the app's project be under source control.
A sum greater than its parts
Xcode 5 combines a number of significant improvements that make life easier for iOS and OS X developers and improve the applications they produce: better source control, faster builds that make faster code, simple gauges that can provide a wealth of insight into the operation of an app, improved automated testing to keep the bugs away. Taken all together, the result is that Xcode 5 makes iOS and OS X code development not only faster, but better.
Xcode 5 is available as a free download from the Apple developer website. To download code to an iOS device you'll need to register as an Apple developer, which requires a $99 fee.
This article, "Review: Xcode 5 makes better, faster, stronger iOS and OS X apps," was originally published at InfoWorld.com. Follow the latest developments in application development and mobile technology at InfoWorld.com. For the latest business technology news, follow InfoWorld.com on Twitter.
This story, "Review: Xcode 5 makes better, faster, stronger iOS and OS X apps" was originally published by InfoWorld .