This applies to the visibility of the contents of @interface . When it is contained in the header file, it is available for other classes to see when they import the header file. When it is contained in the implementation file, the contents are available only for this implementation file. Usually, when it is declared in the implementation file, it is executed through the class extension (i.e., @interface ClassName () , () stands for class extension / anonymous category), although a named category can be used if desired.
There are several reasons why this is done. The main thing is to define private variables or instance properties. You do not want them to be exposed to anyone who imports the header file, but you need a place to store internal information. For example, this will allow m_isActive to be used only in the implementation:
@interface Class () { BOOL m_isActive; }
You can also override readonly properties declared in the header file so that the implementation file has readwrite access to it when using dot notation. For instance:
Title:
@interface Class @property (nonatomic, readonly) NSString* name; @end
Implementation:
@interface Class () @property (nonatomic) NSString* name; @end @implementation Class ... self.name = @"WDUK";
Another popular use is a private announcement that you comply with certain protocols, which are implementation details and should not appear in a public header file. For example, when an implementation uses an object that requires it to be a delegate, and you do not want to pollute the header file with a protocol that is not used outside the class.
Other uses (which were left in the dark with recent LLVM / Clang improvements) were to define private methods. This is no longer necessary, since the compiler will look for methods that are not declared in the corresponding header file and assume that they are private to the class and declare them themselves.
The key part, taken from all this, is that everything inside the @interface inside the header file (except for the instance variables defined there via @protected or @protected ) is publicly available, and everything that is contained in the implementation file.