TheLearner
TheLearner

Reputation: 19507

How do I know when do put my properties and methods in the .h file and when to put them in the .m interface?

How do I know when do put my properties and messages in the .h file and when to put them in the .m interface?

I am thinking messages which are public like init should be in the .h file. What about properties which describe the class e.g. configuration type etc.

Upvotes: 4

Views: 86

Answers (2)

rishi
rishi

Reputation: 11839

When you want to restrict access of any property, you can define that in .m file using class extension etc.

There is no as such rule defined for putting properties in .h or .m file, you need to check which properties you want to access outside the class(define those in .h) and which you do want to access outside(define in .m).

Upvotes: 2

Michael Dautermann
Michael Dautermann

Reputation: 89509

According to the Apple docs, one declares properties in "@interface" (.h) files. If you want to have private object only variables, those are called ivars and you wouldn't synthesize accessors to them.

Private properties (or "property redeclaration" in the docs) can be used in things like class extensions or protocols.

Upvotes: 1

Related Questions