• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Circular references
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Circular references


  • Subject: Re: Circular references
  • From: Joar Wingfors <email@hidden>
  • Date: Sun, 13 Sep 2009 15:08:36 -0700


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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Circular references
      • From: DKJ <email@hidden>
References: 
 >Circular references (From: DKJ <email@hidden>)

  • Prev by Date: Circular references
  • Next by Date: Re: Circular references
  • Previous by thread: Circular references
  • Next by thread: Re: Circular references
  • Index(es):
    • Date
    • Thread