In this series, Tools For Devs, I’m going to highlight a few tools that have made my life easier as a developer. The first tool I want to highlight is one that I can’t believe I went without for so long. It’s called Accessorizer and if you haven’t seen it before or you have but haven’t bought it yet, pay attention to this post.
As you may know, Ray Wenderlich and I have hosted a few iOS Programming 101 workshops and one of the things that I constantly see people new to objective-c struggling with is syntax and typing the same darn thing over and over again. You know what I’m talking about, in Xcode 3, every time you needed to create a variable, you needed to type the same things for each variable:
@property (nonatomic, retain) *sampleVariable;
Now if you know anything about me, I like to think I’m an efficiency elitist. My day-to-day work life centers around getting things done in the fewest possible manual steps so that I can do other things, and by other things, I mean find other tasks that can be simplified, scripted, and reduced. The other way of looking at this is that I’m extremely lazy and don’t like to do work so I will find every shortcut known to man. Almost immediately, I figured there had to be a better way. Anytime you are doing something more than a few times, there is a way to replace it with some computing logic. (See a funny story at the end of this post not related to computing but related to efficiency)
At this time, I was only familiar with TextExpander and this seemed like a good tool for the job. So I created a few shortcuts that would pound out each of these lines in less characters. For instance, I would type:
@property (nonatomic, retain)
That worked well enough for a little while but I still felt like there was a better way. That’s when someone mentioned accessorizer to me. I’ll be honest, I went to his website and there was a video and some pdfs and some nice quotes, but I still didn’t know what it did. So I blew it off for a few weeks. Then I heard someone mention it again and this time I watched the video and I didn’t quite understand what it was. Kevin was targeting an audience with much more experience with Objective-C than I had at this time and I felt like I didn’t get it. So let me sum it up for you:
Accessorizer makes it dead simple to:
- Declare properties
- Synthesize properties
- release properties
The hardest part about accessorizer is just getting it configured. After that, it’s a breeze to use.
But the steps to use it are easy:
- Declare your instance variables, e.g.
- Select all of your instance variables and hit command-c to copy them to the clipboard. That’s right folks, accessorizer will work with all of your instance variables at once.
- Move your cursor to where you want accessorizer to insert the property code (after the close } bracket of the @interface area)
- Hit your handy shortcut key for accessorizer, I used ctrl+comman+shift+0, yeah it’s a handful but xcode 4 took over all the good shortcuts.
- This will bring up the accessorizer shortcut window, hit 1 or click on “Declaration”, and this will create your properties:
@property (nonatomic, retain) NSString *someString;
@property (nonatomic, retain) NSMutableArray *someArray;
- and like Emeril says, “Bam!”
- Now switch to your .m file, and place your cursor under the @implementation statement, now hit ctrl+command+shift+0 again and hit 2 and you’ll get:
@synthesize someString = _someString;
@synthesize someArray = _someArray;
- bam! again. Notice how Accessorizer is smart enough to detect the prefix “_” on the instance variable.
- Now we have to release these two, we can’t have any memory leaks! So move your cursor into the dealloc method and hit those magic keys again and hit 4 for dealloc.
self.someString = nil;
self.someArray = nil;
- bam! bam!
I like math so let’s figure out what we saved.
The Old Way:
279 characters typed.
69 characters typed.
That’s a savings of 210 key strokes!!!! And that doesn’t take into consideration mistyping.
You would be crazy not to use this tool. Oh and I haven’t told you the best part, the price: $9.99!! It will pay for itself on the first app you build with it when it saves you all those key strokes. Time is money people. Accessorizer is on the top of my list when people ask “Is there an easier way to do this?”
BONUS FUNNY STORY
So I’m a photographer in my spare time and I went to this workshop by a well respected wedding photographer. Whenever you are shooting professionally, you snap away so you don’t miss the shot. You’ll take 1,000+ photos an hour and you need to quickly cull through these to find the keepers. He was telling us that his method of editing, he gives anything that’s a keeper 1-star. Someone spoke up and said “Why do you give them 1 star, shouldn’t you give them 4 or 5 stars?”, and his response was fantastic (and well prepared, a little too prepared now that I think back on it, I wonder if the question was a plant). His response, “The 1 key is closest to the tab key, which is what you use to go to the next photo, if my finger had to reach all the way to the 5 key, it would be extended and worked an extra 4-5 inches. I edit 4-6,000 photos per wedding and I keep about 4-500 (10%) so by reaching the 1 key instead of the 5 key, I have saved my finger from traveling an additional 4-500 inches per wedding. I shoot 30+weddings per year, that’s 15,000 inches, 1,250 feet, or almost a 1/4 mile.”