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