views:

603

answers:

6

Coming from an Eclipse / Java background, one of my favorite features is the ability to quickly stub out all the methods required by an interface. In Eclipse, I can choose 'Override / implement' from the source menu to generate stub methods for any method of the Interface.

I'd like to do the same thing in Objective-C. For instance, if I declare a class that implements the 'NSCoding' protocol, I'd like to have XCode automatically generate the methods required to implement this Protocol. It's frustrating to have to look-up and then copy/paste the signatures of the required methods every Protocol that I'm trying to implement.

I've been trying for awhile to find out if this is possible, but haven't found anything promising yet. Is this possible in XCode?

+1  A: 

Your can create scripts for the scripting menu item in AppleScript, Perl, Python, Ruby, or any other scripting language that go in the scripting menu.

Your could place the insertion point in the .m file and have the script look up the corresponding .h file. Locate the protocols supported and so forth...

MacTech ran an article in 2007 Xcode Menu Scripts

Niels Castle
A: 

Xcode 3.2 will autocomplete known method implementations. In other words, if the method is declared somewhere (for example, in a protocol), when you start to type it in a .m file, Xcode 3.2 will autocomplete the method signature for you. This isn't quite what you asked for, but it is awfully handy.

Kevin Ballard
+3  A: 

I believe that Accessorizer will do what you want.

jessecurry
+2  A: 

Accessorizer will write the encode and decode methods for ivars passed to it (NSCoding protocol and for NSDocument archiving). It will also generate string constants either static or #define with a custom prefix; copyWithZone:; and other things if you need - all from a simple shortcut via Services or from the toolbar. Accessorizer keyed archiving

Kevin
A: 

I'm also looking for a way to generate method stubs for the protocols in my header file. I checked out Accessorizer and it looks to be a handy tool but unless I missed something I didn't find a way to get it to generate method stubs for a protocol.

Eric, If you found another solution please post what you found. It's amazing to me that XCode doesn't already have this built into the IDE.

Brad
A: 

Based on AllanCraig's "Create @property, @synthesize & dealloc from Variable Declaration" ruby script, I made one to generate implementation stubs from interface ones: http://pastebin.com/4T2LTBh6

How to use?

  • Setup the script on your XCode (Shell Script) and assign a shortcut for it (e.g. CMD+5).
  • Select lines from your interface file in which you want to generate the implementation, and press the hotkey.
  • Your .m will contain your selected methods.
AlfredBaudisch