views:

56

answers:

1

Hello,

Beginner question here. In the .h file of an objective c class..

  1. If you have an @property int someVar; for example.. and you're actually going to write the setter method yourself in the .m file.. do you still have to declare that setter method in the .h file?

  2. If you have some @property declarations in the .h file and you are writing the getters and/or setters yourself.. you don't have to @synthesize them, correct? And if you don't synthesize them, do you have to declare them in the .h file or does the fact that making them properties is sufficient?

+1  A: 
  1. No, you don't have to define them since they already are defined. Defining a property implies that there will be a setter method – unless that property is readonly.

  2. Just replace the @synthesize with @dynamic and implement getter and setter yourself.

Pascal
If you implement the setter/getter yourself, there is no need to have `@dynamic` for the property.
bbum
but would you still need an @property or is it optional?
Ayrad
To expand on bbum's comment, the `@dynamic` is only necessary if the methods will be added at run-time, which can happen, for example, with subclasses NSManagedObject (i.e. when using CoreData).If you implement both the setter and getter yourself, then you don't need either an `@synthesize` or a `@dynamic`. But you do still need the `@property` in the header file.
Kelan
@Ayrad: You need the `@property` in order to be able to use the dot-notation, otherwise the compiler will complain.
Pascal