Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode: Possible to auto-create stubs for methods required by Protocol interface?

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?

like image 701
Eric Farraro Avatar asked Nov 07 '09 20:11

Eric Farraro


3 Answers

I believe that Accessorizer will do what you want.

like image 90
jessecurry Avatar answered Sep 24 '22 12:09

jessecurry


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

like image 7
Kevin Avatar answered Sep 23 '22 12:09

Kevin


Not the direсt answer, just hint:

Out of the box XCode can't.

But AppCode can.

It can do this things automatically (with your permission, of course).

If some methods of protocol marked as @required - AppCode will highlight the implementation and suggest to implement this methods.

example

@optional methods also available to implement automatically (shortcut: control + I).

like image 6
skywinder Avatar answered Sep 22 '22 12:09

skywinder