Saving Time in Xcode with TextExpander
July 7th, 2008When you are coding there are a lot of things you type over and over again - (void)awakeFromNib springs to mind as well as a few others. I am a great fan of doing as little typing as possible, I would like to be able to say that this is because it allows me to focus on the purpose of the code I am writing, but really it is just plain laziness. What?! I’m a teenager!
So I am a big fan of auto-complete in Xcode. I am also a big fan of the macros in TextMate, but I would rather have the auto-complete. So I turned to TextExpander, something I have been using for a while to relieve me of some of my typing duties.
What I came up with is a set of TextExpander snippets that are in their infancy but that I have been using for a week and am loving. For someone who has never coded 9-5, 5 days a week before, these are really helping ease me into it! (I of course have coded for that length of time, just more in the 7pm - 4am category).
I would love to see some other developers add to the list but here is what I have so far:
These are not just those words, oh no. These are full methods and statements that make use of TextExpander’s wonderful ability to position the cursor where you like once it has expanded. For example when I type “iinit” the following appears:
- (id)init
{
if (![super init])
return nil;%|
return self;
}
(That has probably come out horribly on wherever you are reading this but theres not much I can do about that right now). Where the “%|” is, is where the cursor is positioned. So after typing “iinit” I am all set to write my initialisation code.
Why the two “i”s? Simply to avoid that expanding every time I want to use an init method! Its a well known TextExpander technique.
A neat trick is that I have different variations for my NSLocalizedString that pastes the contents of the clipboard into the the relevant slot. So if I have been given a localizable.strings to deploy I just copy which string I need and type “lllocal” (two “l”s and it doesn’t paste the clipboard, just moves the cursor). TextExpander does its magic and a lot of effort is saved. I do a similar thing with time stamps in my headers.
This has only been a week of me really thinking about this so I have no doubt the collection will grow but I really want to see some suggestions for different snippets. I don’t usually get many comments from you developers out there but consider this a call to arms! What would you like to see in the snippets set.
I have uploaded the set of snippets and it is a freely available to download, use and edit as you wish. To install open up the TextExpander preference pane, choose the “+” drop down and select “New Group from File…”. Then simply choose the .textexpander file you downloaded.
I hope this is as much use to you lot out there as it is to me and please let me know all the obvious snippets I’ve missed!
It has been a while since my last review for 
