Friday, June 13, 2014

Xcode Code Snippets are Awesome

Image: Apple, Code Snippets
I am working on a project where I am writing a lot of test cases. I inherited a test suite that is far behind
the tests suites of the other platforms this project is supporting. As such I have been assigned to get the Mac and iOS test suites up to par with the other platforms.

So, as part of this I am adding a lot of test cases and that means a lot of new methods and chunks of similar code are being added. So, I finally have a good reason to use Xcode Code Snippets again and boy do they rock. I'd forgotten how helpful they are.

The best source for how to use Code Snippets in Xcode is the Apple docs.

I am using them to make a first pass through our test classes to add stub methods for all of the missing test cases that are on other platforms. No cut and paste, with the shortcut I added "misstest", I just start to write misstest and the code completion option comes up and I can drop in a new missed test block of code.

Then I just go through and edit each one with the new test case by porting the tests from other platforms into the Mac and iOS test cases. The snippet also allows me to customize a test case snippet for the additional setup we do like stubbed log statements, test naming convention, etc.

It is a great little optimization to get more done with less typing and cut/pasting.

Try it out if you have something repetitive you need to write.

No comments: