Xcode for Drupal

The next step is setting up the code formatting to match Drupal's two-space indentation standard. Unfortunately, Xcode is not flexible in this regard: there is a global setting, accessible at Preferences... > Indentation, and a per-file setting, available at View > Text > Tab Settings.... Pick your poison. Here I miss Visual Studio, which enables different settings per language.

I happen to be a big fan of tabs myself, and since Drupal development is only a small part of my work I've taken the per-file approach. To make sure I stick to the standards I use Drupal's Coder module, which I recommend.

That's all the setup. Now you can create a new project in Xcode using File > New Project.... Choose the Other group and Empty Project. Save it where you want it. Then choose Project > Add to Project... and choose all the files or folders at the root level of your Drupal installation (or whatever subset makes sense to you) and click Add. You can keep the defaults for the References dialog -- to be honest I'm not sure what all these settings mean quite yet, but the defaults are working fine for me.

Then, in the Xcode project outline, select all of the files and folders at the top level of the project. Hit Command+I to bring up the Inspector and set the tab settings as described above. These will be applied recursively to all of the objects in the projects.

And that's it! You might try playing with the different layouts in Preferences > General to see which you like best; I've settled on "All-In-One".

If, like me, you are just getting started with Xcode, these links might be helpful. I'll update the list as I discover new ones and please, if you know of a helpful site post it in the comments below. And be sure to check out the built-in help, which is actually pretty good.

I found these sites useful in figuring out the Xcode internals for this article:

AttachmentSize
drupal.pbfilespec453 bytes

Did you enjoy this article?

Help me write more like it. »

Thanks!

Brilliant intro. I've just started doing drupal dev and use xcode as my default editor, this is gonna help me loads!

Thanks for posting this.

The idea of using Xcode with Drupal was lurking around in the back of my head. I've been having trouble getting Eclipse set due the error "Standard VM not supported on MacOS", even though the standard VM came bundled with Mac OS X 10.5.7.

I'll let you know if i have better success with Xcode.

Starkos,
I've installed Xcode and it appears that the following path does not exist:
~/Library/Application Support/Developer/Shared/Xcode/Specifications

Any suggestions?

Thanks.

Assuming you've got the main part of the path ...Developer/Shared/Xcode go ahead and create the Specifications folder.

Thanks, Starkos.

I didn't see your reply until after i posted my additional comment.

Hi Starkos.

I didn't get anywhere after i got drupal.pbfilespec set up on the correct directory.

For example, clicking on index.php in eclipse was enough to get the debugger started. No such luck here. I can't seem to designate index.php as a target nor as an executable.

When I look at all my files from drupal, there is no hierarchy of directories; there just seems to be one flat folder with all the files.

Strange stuff. Hard to believe that xcode won't offer any suggestions on setting a PHP/Drupal project.

At the moment, i'm just using Komodo Edit and $output .= dsm($something).

How about yourself? Have you gotten anywhere?

As far as I know, you can't run/debug PHP from Xcode, you can only use it as an editor (like Komodo Edit).

Use the project outline, in the left sidebar, to navigate the file hierarchy, just like in Eclipse. That weird pane above the editor shows all of the files at or below your current location in the outline. It doesn't make any sense to me, and I just hide it to make more room for the editor—just drag the splitter up to the top of the window.

I'm not doing very much PHP development right now, mostly just tweaks to Drupal, so Xcode has been sufficient for me.

I now realize that you must create the directory yourself. I came across this article: Exending Xcode - File & Project Templates, TextMate Style Macros, which says:

When Xcode boots it scans through a few different directories to put together its runtime environment. One of the last directories that it scans is ~/Library/Application Support/Developer/Shared/Xcode. This directory contains user specific Xcode extensions. If this directory does not exist, you will have to create it. This is where you will place project templates, file templates, and macro specifications.
(emphasis mine)

Once I placed the file drupal.pbfilespec in this directory and started up Xcode, i was able to see text.script.php and text.script.php.drupal.

However, when reviewing file types, i do not see *.module, *.install nor *.inc. Should i be seeing something like text.script.php.drupal.module?

Have you actually been able to debug your drupal code in xCode?

I can't figure how to do this. It appears that i may need a target and/or an executable.
In Eclipse you would point to a PHP Executable. Would this be the same in xCode.

What about the target? Would this be index.php?

Would a php project be similar to an Applescript project?
Apple mentions php, but gives no details on setting up a project, on debugging, etc.

Thanks.