On 13 sep 2009, at 15.00, DKJ wrote:

I've got a MyViewController and a bunch of MySubview objects that are subviews of its view. I want MyViewController to keep track of certain things, such as the last MySubview that was clicked. So MySubview has to know about MyViewController to tell it it's been clicked; and MyViewController has to know about MySubview to define the property for the last-clicked subview.

But if I put this in MySubview.h:

  #import "MyViewController.h"

and this in MyViewController.h:

  #import "MySubview.h"

I get errors.

What's a good way to deal with this situation?

I know this must be a very basic question, but I don't even know what terms I should google to find out about it.


In general, try to keep your header #includes / #imports to an absolute minimum. For ObjC you can accomplish this by using forward declarations:

Foo.h
==========
@class Bar; // <- Forward declaration of the Bar class
@interface Foo : NSObject {
        @private
        Bar *_bar;
}
@end
==========

Foo.m
==========
#import "Bar.h" // <- The forward declaration is "resolved" here
#import "Foo.h"
@implementation Foo
@end
==========


j o a r


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to