0

I am new to objective c

All the time i read something about properties and delegates

@synthesize something;
@property (nonatomic, retain) IBOutlet something<Something> Something;

While my program gets bigger and bigger i find myself not using this at all and everything is working just fine.

so my question: what are properties for? Whats there advantage over normal variables with getters and setters?

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
asdf
  • 1,475
  • 1
  • 9
  • 11
  • Possible duplicate: http://stackoverflow.com/q/11478038/294661 – Peter Warbo May 20 '13 at 11:54
  • Aww... sry for that... – asdf May 20 '13 at 12:10
  • I guess the question should be: why do so many people use properties for everything, including internal variables that aren't exposed anywhere and would be accessed much quicker, and with less typing by using ivars! (And sadly the answer would be that many new Objective-C programmers don't understand the difference between an ivar and a property, and use a property because the dot syntax looks like Java or JavaScript...) – Guillaume May 20 '13 at 15:19
  • @Guillaume I like using properties before iVars since I future proofs my code. I could use a ivar for "zipCode" but using a property allows me to use custom getter/setters without my code knowing the difference. – John May 20 '13 at 18:09

1 Answers1

2

Properties are normal variables with getters and setters, but provide a much shorter way to write them.

  • And they provide proper memory management while also helping to make KVC and KVO easy to implement through predictable compliance. – uchuugaka May 20 '13 at 11:56
  • Do normal Variables not get cleaned from the garbage collector? – asdf May 20 '13 at 12:04
  • 1
    @asdf Yes, though the garbage collector is a rare and deprecated configuration for Objective-C environments. Most code you come across will be either manually reference-counted or use automatic reference counting (ARC). –  May 20 '13 at 12:13