Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto generate stubs for protocols in XCode 4.2?

Tags:

xcode

ios

Can Xcode 4.2 auto-generate me the stubs for the protocols i defined in the header-file?

In this tutorial (http://kurrytran.blogspot.com/2011/10/ios-5-storyboard-and.html) in the note of point 4 the author says, Xcode will now auto generate the methods i need. Otherwise I did something wrong...

like image 700
rakete Avatar asked Nov 02 '11 19:11

rakete


4 Answers

From your question, I can't understand exactly what you need.

If you need boilerplate code like the -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath implementation that comes when you subclass UITableViewController, then you should create your own templates as Grouchal suggests. Also check a similar question I asked here.

I think that the tutorial you link to refers to code sense, for example:

  • In a header file, add a protocol like <UITextFieldDelegate>:

@interface FirstViewController : UIViewController <UITextFieldDelegate>

  • Save, and then in your .m file, you can see the new methods that you can implement just by typing a dash "-" and then pressing "Escape" on your keyboard. It helps if you type the first letters, for example "-tex" and then "Escape" will display the methods of the UITextFieldDelegate.

Try the same with UITableViewDelegate and UITableViewDataSource, you will see that you'll get a similar result as the one at step 4 of your tutorial (note that in the screenshot, the user has already typed "-tab" to get the list of methods).

like image 77
phi Avatar answered Oct 14 '22 02:10

phi


Check out Accessorizer if I'm not mistaken, it can do what you want.

like image 41
PTBG Avatar answered Oct 14 '22 02:10

PTBG


Firstly you might want to look into using templates to achieve your goals:

http://blog.highorderbit.com/2009/03/15/customizing-xcode-cocoa-touch-file-templates/

The tutorial you have references also mentions in point 4:

Also note, if the method is not auto-generating you're probably doing something wrong. That's the main way I know I'm doing something wrong, or the program crashes.

This might indicate that you have not followed the previous steps 100%

like image 25
Grouchal Avatar answered Oct 14 '22 00:10

Grouchal


If you create a new class through the Xcode wizard ( i.e. File->New->File or cmd-N and select Objective-C class ) then if you pick an appropriate built-in superclass from those in the 'Subclass Of' dropdown, you will get a template implementation with the essential stubs implemented, and commented-out versions of other methods, that you can base your code on. I've used this successfully for subclasses of UITableViewController. Not quite in the league of the Eclipse stub generation, but better than nothing.

like image 21
JulianSymes Avatar answered Oct 14 '22 00:10

JulianSymes