Alex Rivera | Logout

Confusion with header and Implementation files in Objective-C

Asked 2009-09-19T22:33:05.103
25

First off, please forgive the stupidness of this question but Im not from a C/C++ background. I'm a little unclear about what the difference in roles between the .h and .m files when it comes to properties.

I understand the concept of interfaces, and I see that in part the .h file is an interface for the implementation, but what I am not clear on is this:

  • Why are properties/methods defined outside of the {} braces?
  • What am i defining in the braces when I write something like this:

    IBOutlet UITextField *numberField;

    Is this a field definition in an interface?

  • When I am adding the @Property lines to the .h files are these actual implementations of a n auto property or just an interface blueprint? If so is the @syntesis the actual implementation?

I guess my biggest confusion seems to be that if I want a property I'm defining what I need in three different places (1) in the interfaces braces, (2) as @property outside the braces and (3) with @synthesis in the .m file. This seems long winded, but its fine if I can work out what these three parts do.

Cheers, Chris.

Edit
Report

1 Answer

0
  1. Well that is just Objective C syntax, methods and @property outside {} and variables inside {}.

  2. @property is the way of telling that you are going to write getter and setters (kind of enforcing it), but you can write getter/setter without setting them @property. @property is in .h file because its declaration. And why it is outside {}, well as i said before its just the syntax, what we can do?

  3. @synthesis will in actual implement getter and setters, if you dont synthesis but you have set them @property, you have to implement those getter and setters by your hand. And @synthesis is in .m file because its implementation.

Something more for you to read on this subject can be find here.

http://theocacao.com/document.page/510

answered 2009-09-19T23:16:23.480

Your Answer