Useful script for Xcode - alloc and init

Discussion in 'Mac Programming' started by idelovski, Feb 4, 2009.

  1. idelovski macrumors regular

    Sep 11, 2008

    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.
  2. MacRohde macrumors regular


    Jun 1, 2004
    Copenhagen, Denmark
    Hey that is pretty cool. I will check it out when I get home. Thanks for the contribution :):)

Share This Page