A way to automatically organize #imports in Xcode A way to automatically organize #imports in Xcode xcode xcode

A way to automatically organize #imports in Xcode


You can do this by creating an Automator action and use that in Xcode as well as everywhere in Mac OS X. To do that, do the following:

  1. Start Automator -> New
  2. Choose "Service"
  3. add a "run shell script" action
  4. use sort | uniq as the script and check the "output replaces selected text" checkbox
  5. save and give it a name (e.g. "sort & unique")
  6. check "Output replaces selected text"

After you saved it, you can just select your imports in Xcode, right click and choose your "sort & unique" action to organize your imports.

This is not as good as the organize import actions in Eclipse or IntelliJ, because it doesn't removes unused stuff etc. but it's better than nothing.

PS: Got that from WWDC 2012 Sessions - Session 402 Working Effeciently with Xcode (starting at 6:15)

EDIT

I started using AppCode, the Objective-C IDE from JetBrains, and it has features like "organise imports". You should check it out: http://www.jetbrains.com/objc/.


I'm resolving this as not currently a feature of Xcode :(


I've found Cedar Shortcuts to at least be usable. It's not as good as Eclipse's import feature (it doesn't organize imports), but it can keep you from having to go to the top of a class file and typing an import statement. With this plugin you just place the cursor on the class that needs imported and press Ctrl + Option + I. Here's the github project. https://github.com/cppforlife/CedarShortcuts