The @interface
in the .h file is generally the public interface, this is the one that you would declare the inheritance in such as
@interface theMainInterface : NSObject
note the colons :
and then the super object that this @interface
is inheriting from NSObject
, I do believe that this can only be done in the .h file. You can also declare the @interface
with a category as well such as
@interface theMainInterface(MyNewCatergory)
So this means that you can have multiple @interface
s in one .h file like
@interface theMainInterface : NSObject
// What ever you want to declare can go in here.
@end
@interface theMainInterface(MyNewCategory)
// Lets declare some more in here.
@end
Declaring these types of @interface
s in the .h file generally makes everything declared in them public.
But you can declare private @interface
s in the .m file which will do one of three things it will privately extend the selected @interface
or add a new category to a selected @interface
or declare a new private @interface
You can do this by adding something like this to the .m file.
@interface theMainInterface()
// This is used to extend theMainInterface that we set in the .h file.
// This will use the same @implemenation
@end
@implemenation theMainInterface()
// The main implementation.
@end
@interface theMainInterface(SomeOtherNewCategory)
// This adds a new category to theMainInterface we will need another @implementation for this.
@end
@implementation theMainInterface(SomeOtherNewCategory)
// This is a private category added the .m file
@end
@interface theSecondInterface()
// This is a whole new @interface that we have created, this is private
@end
@implementation theSecondInterface()
// The private implementation to theSecondInterface
@end
These all work the same way, the only difference is that some are private
, some are public
and some have categories
I am unsure if you can inherit on an @interface
in the .m file.
Hope this helps.