Q: What exactly are ... header files
A: Header file - is a file, content of which compiler 'inserts' instead of #import...
(#include
and other similar directives) line. Header files contains public code: forward declarations of classes, enums, variables, functions and other and other.
Q: What exactly are class extensions …
A: Class Extension
- is a language construct, which allows you to extends the interface to the class.
To better understand what it is you must understand what is a class category
.
Category
- is a language construct, which allows you to add functionality (methods only!) to existing class. Even without subclassing.
Example:
You can add new method to NSImage:
@interface NSImage(YourExtensionName)
- (CGImageRef)CGImage;
@end
A Class Extension
(also known as a class continuation, or unnamed category
) bears some similarity to a category, but it can only be added to a class for which you have the source code at compile time.
In class extension
you can use same things you use in a usual @interface
block.
Q: What are difference
A: Header file uses for include to your program some ability (structures, data types, constants, functions and so one). Class extensions uses for extends existing class with some functionality. Usually, class extension
is a private interface of a class. The functionality declared by a class extension
are implemented in the @implementation block for the original class so you can’t, for example, declare a class extension on a framework class, such as a Cocoa or Cocoa Touch class like NSString.
Q: What is the difference between declaring a property/method in a header file vs in a class extension
A: If you declare property/method in header file, then any user of .h file can access to this property/method. Class extensions uses for declare private interface for you class.
I strongly recommend to you read Apple's Objective-C Programming Guide.