1

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.

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh my. I must be tired. I did not find that it's a different definition. Totally missed the "ContentView" in the end of the name. Thanks for pointing out.
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.