4

hopefully this is an easy one.

I'm coding in objective-c and i'm wondering if there are any tools/tricks (anything) that you use for this annoyance (see below).

Is there an easier way to declare variable/properties within the header and implementation files?

e.g., I'm not a big fan of typing this in the header:

NSString *commercial_name;

@property (nonatomic, retain) NSString *commercial_name

and then typing

@synthesize commercial_name

in the implementation

it's quite tedious when all 3 things are needed (or when I have to delete all 3) and I'm wondering if there's a plugin (or something) where you can simply say, I'm going to have a variable called foo of type bar and I want getter & setter methods for it. poof it's done.

TYVM!

user141146
  • 3,285
  • 7
  • 38
  • 54
  • BTW: "commercial_name" should be "commercialName". – bbum Sep 12 '09 at 18:23
  • 1
    @Philippe: It's a universal convention. Many Cocoa features actually depend on things being named that way. – Chuck Sep 12 '09 at 19:13
  • 2
    Says Apple. Check the conventions for ivar naming and method naming: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingMethods.html#//apple_ref/doc/uid/20001282-BCIGIJJF . A number of builtin things like KVC and KVO actually depend on the name conforming, and if they don't you have to write extra code to deal with it. – Louis Gerbarg Sep 13 '09 at 02:00

4 Answers4

4

On the iPhone, which uses the "modern runtime", you can ommit the ivar (field declaration). Simply declaring and synthesizing the property is enough. The ivar is created at runtime.

More info here (at the end of the page):

https://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html

Another discussion:

Using instance variables with Modern Runtime

Sadly, this mechanism doesn't work in the iPhone simulator, not even in Snow Leopard :-(

Community
  • 1
  • 1
Philippe Leybaert
  • 168,566
  • 31
  • 210
  • 223
  • 1
    The new Objective-C runtime is 64-bit only, and it looks like the iPhone Simulator isn't yet 64-bit on Snow Leopard. – Brad Larson Sep 12 '09 at 20:00
3

I'd check out Accessorizer: http://www.kevincallahan.org/software/accessorizer.html

Dave DeLong
  • 242,470
  • 58
  • 448
  • 498
0

there are autocompletion scripts (like typing 'log' and then pressing Cmd + . to autocomplete this to NSLog())

you could build one that would insert these three lines and you'd need to provide only the name and type for the property.

Eimantas
  • 48,927
  • 17
  • 132
  • 168
0

Check out the following link, he has written an Apple Script which you can use in XCode and he has put the video as-well for us to see how to use it properly!

http://allancraig.net/blog/?p=315

itsaboutcode
  • 24,525
  • 45
  • 110
  • 156
  • Also check out some great tools for lazy Objective C programmers like me lox http://github.com/holtwick/xobjc/tree/master – itsaboutcode Sep 12 '09 at 19:00