What is the logic for placing @interface in a .m file?

Possible duplicate:
Difference between @interface definition in .h and .m file
What is the @interface declaration in .m files used in iOS 5 projects?

I saw a code like this:

// In Header.h @interface Header{} @end // In Header.m @interface Header() @end 

My questions:

  • What is the difference to put it in 2 files?
  • Why put {} after the class name in the ".h" file and why "()" in the ".m" file?
+8
objective-c
source share
2 answers
 @interface MyClass(){ NSInteger aInt; } @property(nonatomic,strong) NSString *name; @end 

- expansion

with modern compilers, this is a great way to decrale methods, ivars, and properties for private use only in the MyClass class.

Class extensions must be declared in the main implementation file (not in the category).

This way you can hide implementation details from the header file, they are private.

+12
source share

It has become common practice to declare "private" properties / methods for a given class. By declaring them in an anonymous class extension inside .m, these properties / methods are not exposed to consuming objects.

+3
source share

All Articles