I came across the following code snippets from Apple’s Documentation.
The Interface is fairly straightforward:
#import <Foundation/Foundation.h>
#import "ApplicationCell.h"
@interface CompositeSubviewBasedApplicationCell : ApplicationCell {
UIView *cellContentView;
}
@end
The implementation:
#import "CompositeSubviewBasedApplicationCell.h"
@interface CompositeSubviewBasedApplicationCellContentView : UIView {
ApplicationCell *_cell;
BOOL _highlighted;
}
@end
@implementation CompositeSubviewBasedApplicationCellContentView
//not important, abbreviated...
@end
I can’t quite figure out why there is another @interface declaration in the implementation file. I assume that it is a way of declaring private instance variable. Am I right?
And since the interface already said that CompositeSubviewBasedApplicationCell extends ApplicationCell, what does CompositeSubviewBasedApplicationCellContentView : UIView mean?
Thanks in advance.
It’s the definition of another class. In most cases, this would be in a separate file, but it’s also possible to define multiple classes in one file, especially if they’re closely related.
CompositeSubviewBasedApplicationCellContentViewis probably not used by any classes except forCompositeSubviewBasedApplicationCell, so it doesn’t need to have its own header file.