views:

538

answers:

3
  • Is there a key shortcut for this in XCode?
  • Can I implement an Applescript for this and run it within XCode?
+1  A: 

You can probably do that using a script (check out the relevent piece of Xcode documentation). Also see the "Insert Text Macro" menu item…

But you might find it to be more efficient to just use the auto-correct feature. I just type "[[F", then hit my auto-correct key (bound to F5 I believe, but I've changed it), type enough of the class name for it to be selected in the autocorrect popup. Hit space, start typing alloc but let auto correct kick in. Close the brace. Start typing init, use autocorrect again.

You generally shouldn't need to create macros/scripts for something this trivial. The autocorrect, placeholders and autofill features should be all you really need.

schwa
A: 

Textmate will auto-back fill ['s for you. You can also build your xcode project from inside it as well as do thousands of other interesting things with the objective-c and other built in bundles that add functionality. It has a 30 day demo, give it a shot and see if it does what you want.

crackity_jones
+1  A: 

I see that this question was asked some time ago. For anyone just stumbling on it, current versions of Xcode (3.2+) will fill in the open brackets for you as you go (what crackity_jones calls "auto-back fill"). That is, if you type

[Foo alloc]<cursor>

and then keep going...

[Foo alloc] init<cursor>

...when you type the next close bracket, Xcode will insert the corresponding open bracket in the correct place:

[[Foo alloc] init]<cursor>

Try it out. While this doesn't answer the original question directly, it does address the need.

rsfinn
That's neat. You can even start with "Foo alloc" and when you press "]", it'll insert the first "[" for you, too. No more left brackets for me! Then we just need to get rid of the right brackets and we'll be back to Smalltalk. :-)
Nicholas Riley