View Full Version : Useful script for Xcode - alloc and init

Feb 4, 2009, 03:42 PM

I wanted to speed up creation of all the "alloc/init" lines I am putting into Xcode every day so I searched a while for some script that would do it for me.

I couldn't find anything so I started experimenting and with a little help of "Xcode Unleashed", page 227, I created this script:

#! /bin/sh
# Create nested allocation and initialization

echo -n "%%%{PBXSelectedText}%%% *%%%{PBXSelection}%%% = [[%%%{PBXSelectedText}%%% alloc] init];"

In Xcode click on the Script menu and pick Edit User Scripts... command.

With this script ready, type some class name, select it and run the script. It will produce alloc/init sequence for given class.

For example, if you type NSString the script will produce NSString * = [[NSString alloc] init]; and put insertion point behind the asterisk where you can type your variable name.

I just hope someone may find this useful. if you have something similar please post it here.

Feb 4, 2009, 03:53 PM
Hey that is pretty cool. I will check it out when I get home. Thanks for the contribution :):)