Reputation: 322
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.
Upvotes: 0
Views: 150
Reputation: 4752
CompositeSubviewBasedApplicationCell
and CompositeSubviewBasedApplicationCellContentView
are two different classes.
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?
Yes, that's a way to make a class completely private. If someone wanted it to be partially private they could just extend it in the implementation file like this:
@interface CompositeSubviewBasedApplicationCell()
@end
Upvotes: 1
Reputation: 53551
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.
CompositeSubviewBasedApplicationCellContentView
is probably not used by any classes except for CompositeSubviewBasedApplicationCell
, so it doesn't need to have its own header file.
Upvotes: 4