Integrating Emacs and XCode

I tend to use Emacs for all my editing, although when I am writing Mac OS/X GUIs, I couple it with XCode for managing the project build process. The main things I've needed to customize in my ".emacs" file is to get Emacs to automatically recognise Objective-C files when they are opened (including Objective-C ".h" files), and have the "compile" command in Emacs call xcodebuild to actually compile the program. To have Emacs recognise Objective-C files, first add the following to your ".emacs" so that ".m" and ".mm" files get handled automatically:
(setq auto-mode-alist
      (cons '("\\\\.m$" . objc-mode) auto-mode-alist))
(setq auto-mode-alist
      (cons '("\\\\.mm$" . objc-mode) auto-mode-alist))
Next add this code so that header files get automatically handled. Finally you can compile using xcodebuild with the following code:
(defun bh-compile ()
  (interactive)
  (let ((df (directory-files "."))
        (has-proj-file nil)
        )
    (while (and df (not has-proj-file))
      (let ((fn (car df)))
        (if (> (length fn) 10)
            (if (string-equal (substring fn -10) ".xcodeproj")
                (setq has-proj-file t)
              )
          )
        )
      (setq df (cdr df))
      )
    (if has-proj-file
        (compile "xcodebuild -configuration Debug")
      (compile "make")
      )
    )
  )