reshefm
reshefm

Reputation: 6167

Do I declare all the instance variables in the .h file in ObjC?

I am new to ObjC.

If I want to declare instance variables for private use of my class, do I do that in the .h file of my class inside the curly brackets?

If I just declare a variable in the body of the .m file, will it result in a global variable?

Thanks

Upvotes: 0

Views: 510

Answers (3)

shreyasva
shreyasva

Reputation: 13456

i think you are getting confused between an instance variable and a class/global variable. An instance variable is part of every object that you create and you need to declare them within the curly braces inside the class interface. If you declare a variable in a .m file it becomes a global variable where each object does not have its own copy but instead is shared between all the objects.

Upvotes: 3

Chris Devereux
Chris Devereux

Reputation: 5473

Yes, declare them in the curley brackets.

http://cocoadevcentral.com/d/learn_objectivec/

Upvotes: 0

Eiko
Eiko

Reputation: 25632

Yes, you need to declare your instance variables in the .h file. You can tag them as private to make your intention more clear.

Upvotes: 2

Related Questions