-6

I've heard about getter and setter methods in Objective C.

They are doing something else that's important, besides making it easier for you to set and get a variable.

What are they doing and how do they do it?

qonan
  • 3
  • 3
  • getters and setters are not just related to Objective C ! http://stackoverflow.com/questions/2036970/how-do-getters-and-setters-work – Nofel Mahmood Oct 24 '14 at 20:02
  • See https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/AccessorMethod.html and its various links. – Rob Oct 24 '14 at 20:07

1 Answers1

0

With setters you set the value of a property in a instance of a class. A getter is a function that gives you the variable as a return when you call it. You use setters and getters to control the access to private properties.

Patricia
  • 2,885
  • 2
  • 26
  • 32
  • "A getter is a function that gives you the variable as a return when you call it." Which variable do you refer to ? – qonan Oct 24 '14 at 21:03
  • @qonan Long ago we used to have to explicitly declare instance variables that the getters and setters use. Nowadays, that practice is discouraged as the compiler will synthesize these instance variables for us. So, up when you define a property called `name` the compiler will synthesize (a) a getter called `name`, (b) a setter called `setName`, and (c) an instance variable (which you generally won't use) called `_name`. – Rob Oct 25 '14 at 00:36