Compiling an iOS/Xcode project from Emacs

I've been learning iOS development, and slowly adding objective-c support to my emacs configuration, since Xcode is ridiculously slow on the ancient second-hand macbook air I've been using. So far objc-mode has great syntax highlighting, and my basic autocomplete setup is functional enough, but it's no fun having to keep Xcode open or switch to a shell to build the project.

This handy little function fixes that by running xcodebuild in the root of your git project:

(defun xcode-compile ()
  "Compiles the current project with xcodebuild"
  (let ((dir (vc-find-root buffer-file-name ".git")))
    (when dir
      (cd dir)
      (compile "xcodebuild -configuration Debug -sdk iphonesimulator"))))

And add a keybinding for it to objc-mode:

(add-hoo 'objc-mode-hook
         (lambda ()
          (local-set-key "\C-c\c" 'xcode-compile)))

Now all I need to add is linting and eldoc support, and I can leave Xcode alone!