importing MyDocument.h compiler errors and warnings

  • In my objects I need to know the document they belong to. To
    accomplish this, I created a reference to the currentDocument upon
    the object initialization. Simplified Code:

    @interface TreeWrapper : NSObject
    {
    NSDocument *document;
    }

    - (id) init
    {
    self = [super init];
    if (self != nil) {
      document = [[NSDocumentController sharedDocumentController]
    currentDocument];
    }
    return self;
    }

    This works fine except it generates compiler warnings as I try and
    call methods that are custom to my subclass of NSDocument. The
    program compiles and runs as expected though.

    If I switch it to MyDocument *document I need to also import
    "MyDocument.h". This causes some sort of error where it can't find
    the TreeWrapper which is the super class to my data objects.

    "error: cannot find interface declaration for 'TreeWrapper',
    superclass of '(one of my subclasses)'

    It generates this for many of my data objects. The problem seems to
    be that including MyDocument.h reincludes my root data object which
    is a sub class of TreeWrapper.

    Anyone have any ideas?

    --Derrek
  • Yep! That did it.

    Is there a basic tutorial documentation that has this kind of
    information?

    I've read a lot of the Objective-c and cocoa basic programming
    tutorials, and I think I have a strong grasp of design patterns and
    other issues, but I keep getting stumped by simple things like this.

    Thanks!

    --Derrek

    On Oct 17, 2006, at 5:58 PM, Ivan Kourtev wrote:

    > Derrek,
    >
    > If I understand correctly, you have an #import "MyDocument.h" line
    > at the beginning of TreeWrapper.h, correct?
    >
    > if so, simply replace it with the following line
    >
    > @class MyDocument;
    >
    > and continue to iimport "MyDocument.h" in "TreeWrapper.m" file.
    >
    >
    > Hope this helps,
    >
    > --
    > ivan
    >
    > On Oct 17, 2006, at 5:52 PM, Derrek Leute wrote:
    >
    >>
    >> In my objects I need to know the document they belong to. To
    >> accomplish this, I created a reference to the currentDocument upon
    >> the object initialization. Simplified Code:
    >>
    >> @interface TreeWrapper : NSObject
    >> {
    >> NSDocument *document;
    >> }
    >>
    >> - (id) init
    >> {
    >> self = [super init];
    >> if (self != nil) {
    >> document = [[NSDocumentController sharedDocumentController]
    >> currentDocument];
    >> }
    >> return self;
    >> }
    >>
    >> This works fine except it generates compiler warnings as I try and
    >> call methods that are custom to my subclass of NSDocument. The
    >> program compiles and runs as expected though.
    >>
    >> If I switch it to MyDocument *document I need to also import
    >> "MyDocument.h". This causes some sort of error where it can't find
    >> the TreeWrapper which is the super class to my data objects.
    >>
    >> "error: cannot find interface declaration for 'TreeWrapper',
    >> superclass of '(one of my subclasses)'
    >>
    >> It generates this for many of my data objects. The problem seems
    >> to be that including MyDocument.h reincludes my root data object
    >> which is a sub class of TreeWrapper.
    >>
    >> Anyone have any ideas?
    >>
    >> --Derrek
    >> _______________________________________________
    >> Do not post admin requests to the list. They will be ignored.
    >> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >> Help/Unsubscribe/Update your Subscription:
    >> http://lists.apple.com/mailman/options/cocoa-dev/<isk_lists...>
    >>
    >> This email sent to <isk_lists...>
    >
  • On 17 Oct 2006, at 22:52, Derrek Leute wrote:

    >
    > In my objects I need to know the document they belong to. To
    > accomplish this, I created a reference to the currentDocument upon
    > the object initialization. Simplified Code:
    >
    > @interface TreeWrapper : NSObject
    > {
    > NSDocument *document;
    > }
    >
    > - (id) init
    > {
    > self = [super init];
    > if (self != nil) {
    > document = [[NSDocumentController sharedDocumentController]
    > currentDocument];
    > }
    > return self;
    > }

    Can I point out that this isn't a particularly good idea.  The
    current document may not in some cases be the document to which the
    objects belong.  Instead, you want methods like:

    - document
    - setDocument:

    in your TreeWrapper class.  Whatever object is responsible for
    creating a TreeWrapper object should do something like:

    TreeWrapper *newTreeWrapper = [[TreeWrapper alloc] init];
    [newTreeWrapper setDocument: [self document]];

    Hope that helps,

    Mike.

    >
    > This works fine except it generates compiler warnings as I try and
    > call methods that are custom to my subclass of NSDocument. The
    > program compiles and runs as expected though.
    >
    > If I switch it to MyDocument *document I need to also import
    > "MyDocument.h". This causes some sort of error where it can't find
    > the TreeWrapper which is the super class to my data objects.
    >
    > "error: cannot find interface declaration for 'TreeWrapper',
    > superclass of '(one of my subclasses)'
    >
    > It generates this for many of my data objects. The problem seems to
    > be that including MyDocument.h reincludes my root data object which
    > is a sub class of TreeWrapper.
    >
    > Anyone have any ideas?
    >
    > --Derrek
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/mike.abdullah%
    > 40gmail.com
    >
    > This email sent to <mike.abdullah...>
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today