Here’s a collection of tips and tricks for dealing with The Xcode Experience™ as your project management needs get complex; we’re quoting some parts particularly novel to us, but all of these are worth reading thoroughly!
Non-code assets for static libraries
There are occasions when static libraries require assets, e.g., images and sound files. Sub-projects and projects in the same workspace share a build directory and Xcode manages the build order of each project so that the main target is always built last. Because of this we can add build phases to our main project and sub-project which copy static library assets into the main bundle…
Improve performance by moving run time operations to compile time
To improve performance move expensive operations from run time to build time and cache the result. This can be achieved by creating an OS X ‘Command Line Tool’ target that runs as part of the bundles build process. Core Data can be used to store the data created at build time (Core Data is cross platform so a Core Data store that is created on OS X can be read by iOS)…
So one bug, that I manage to repeat just about every project, is errors with the constants that reference resources. I get the names of PNG files, tags and identifiers wrong all the time. Or I change the name in the resource, even something simple like capitalization. Fortunately with enough testing these errors come to light. But I’ve also solved this problem before. And in a way that uses the compiler to test for some form of correctness. The simple solution is to create a process that preprocesses the resources and creates a source file with all the constants.
But how to drive the preprocess? Xcode custom build phases and custom build scripts are nearly ideal for this type of work…
In which a method is presented for reliably building static libraries with subprojects in Xcode, and it is suggested that this method, combined with Git submodules or other similar mechanisms, provides the best way to share libraries, frameworks, or other code between projects…
…Use the preprocessor to rename the symbols automatically during the build phase. This is done by adding a series of -DOldSymbol=NewSymbol flags to the ‘Other C Flags’ build setting – like -DTPCircularBuffer=ABCircularBuffer, for instance…
1. It’s run when a shared library is loaded, typically during program startup… NOTE: Although this syntax is specific to GCC, LLVM and Clang have been written to support it as well, and code compiled using Clang-LLVM seems to work just like GCC-compiled code.
…You won’t find this feature in Apple’s documentation. But it does exist in the form of a user-defined build setting called EXCLUDED_SOURCE_FILE_NAMES and it’s a really handy feature. I’ll use TestFlight in this example but you can use this approach to exclude any files from a build…
…This project provides an API for editing Xcode projects. Through the API you can perform many different manipulations directly through code such as adding a file to a project, adding frameworks, and more…
And to finish up with one on working practices, for those of us still finding Xcode 4 gets in our way more often than Xcode 3 did:
(maybe) is a good way to put it, yes. But it is becoming less loathsome with some work setting up designated tabs, we’ll grant that much.
And so is UncrustifyX.
benoitsan / BBUncrustifyPlugin-Xcode uncrustifies the open file.
Injection for Xcode changes code at runtime!
garnett / AutoresizeMask-for-Xcode shows resize masks created in code
KSImageNamed: Xcode autocomplete for imageNamed
ColorSense for Xcode shows colours in a popup
questbeat / Lin: “completion for NSLocalizedString and localizedStringForKey:value:table:”
SCXcodeMiniMap “is a plugin that adds a source editor MiniMap to Xcode.”
DerivedData-Exterminator: “Xcode plugin to exterminate the current project’s DerivedData directories”
Alcatraz “is an open-source package manager for Xcode. It lets you discover and install plugins, templates and color schemes without the need for manually cloning or copying files. It installs itself as a part of Xcode and it feels like home.”
brennanMKE / Xcode4CodeSnippets is a great collection of … snippets.
rayh / xcoder: “ruby wrapper for Xcode build tools to aid automating builds”
facebook / xctool “is a replacement for Apple’s xcodebuild that makes it easier to build and test iOS and Mac products.”
krzysztofzablocki/crafter: “Crafter – setup your cocoa projects with ease.”