PDA

View Full Version : Auto Generate Getter/Setter Methods?




Vortec4800
Apr 15, 2008, 10:40 PM
Is there a way to get Xcode to generate getter and setter methods for a bunch of instance variables? I've got around 20 of em and it's sure tedious to do it for each class...



Spike099
Apr 15, 2008, 11:01 PM
There are a couple of methods to achieve this.

First and Recommended.
Synthesizing, it would be best to read about this in the documentation (http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_5_section_2.html#//apple_ref/doc/uid/TP30001163-CH17-SW13).

Second, if you just want a quick and dirty way to do it(the old way), however this could be used with dynamic synthesizing aswell.
In the menu bar in Xcode, you'll see a script menu. Highlight the variables that you would like the getter setter methods for, select script menu -> code -> Place accessor Decls on Clipboard / Place accessor Defs on Clipboard

Then paste into your interface and implementation files appropriately.

Vortec4800
Apr 15, 2008, 11:38 PM
Fantastic. Thank you!!