Objective-c getters / seters & variable / property declarations - an easier way?

hope it is very simple.

I code in objective-c, and I wonder if there are any tools / tricks (anything) that you use for this annoyance (see below).

Is there an easier way to declare variables / properties in header and implementation files?

for example, 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 implementation

This is pretty tiring when all 3 things are needed (or when I need to remove all 3) and I wonder if there is a plugin (or something) where you can just say I will have a variable called foo like bar , and I want to use getter and setter methods. that was done.

TYVM!

+4
source share
4 answers
+3
source

On an iPhone that uses a β€œmodern runtime,” you can omit ivar (field declaration). Simply declare and synthesize a property. Ivar is created at runtime.

More details 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 using modern runtime

Unfortunately, this mechanism does not work in the iPhone simulator, even in Snow Leopard: - (

+4
source

autofill scripts exist (for example, typing "log" and then pressing Cmd + to autofill this NSLog () file)

you can create one that inserts these three lines, and you only need to specify the name and type of the property.

0
source

Check out the following link: he wrote an Apple Script that you can use in Xcode, and he put the video as good for us to see how to use it!

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

0
source

All Articles