Sort Obj-C Methods with Automator

September 21, 2012


Big view controllers in big projects tend to accumulate a lot of private methods and properties. In a perfect world, these methods and properties should be carefully organized into functional groups and carefully documented. In the world we actually live in, that shit doesn’t happen, which is why I’ve resigned myself to organizing everything alphabetically.

To make my life easier, I created an automator service that sorts everything for me. Here’s how you create it yourself:

  1. Open Automator.app
  2. Create a new workflow and select “Service”
  3. Drag the “Run Shell Script” workflow into the workflow pane.
  4. Above the workflow, change the drop downs to read “Service recives selected text in Xcode” and check the “Output replaces selected text” box.
  5. Change the shell drop down to “/usr/bin/ruby”
  6. Paste the gist below into the text view.
  7. Save the service with an appropriate name and you’re done!

{% gist 3759637 %}

Keep in mind that any comments need to be inline and all method names need to be on one line, no splitting accross multiple lines. I’m not too concerned about this, as it fits my style (I have word wrap turned on) and since nobody ever reads comments on declarations in the .m file anyway. When I get a chance I’d like to update this to clean up property declarations (all the names at the same tab-stop) and remove extraneous spacing in method declarations.

« | Home | »