Search code examples
objective-ciphone

@properties question on iPhone development


From what I've read, @properties and @synthesize are used to tell the compiler to to generate getters and setters for various properties of our class.

So I am confused when I see the source code of an Apple example, the GKTank, that uses only one class for the whole game (apart from the app delegate) and still most of the attributes of that class are defined in @property() and are synthesized, even if no other class will try to get/set them. What am I misunderstanding here?


Solution

  • Using properties is generally good practice as the synthesized setters will do the right thing when it comes to memory management (retain, or simply assign, depending on how you've configured your property).

    They are also a means of providing a clean separation between the public interface of your class and it's internal implementation.

    This article offers some good advice on when and why to use properties and dot-notation.