• 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: Parent-Child References
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Parent-Child References


  • Subject: Re: Parent-Child References
  • From: mmalcolm crawford <email@hidden>
  • Date: Fri, 14 Apr 2006 19:27:39 -0700


On Apr 14, 2006, at 5:55 PM, Jason Barker wrote:

I have a subclass of NSView (myView) with an NSMutableArray (myArray) of objects (myObject).

You should typically give classes a name that begins with a capital letter.
<http://developer.apple.com/documentation/Cocoa/Conceptual/ CodingGuidelines/index.html>


When an instance of myObject is created, I want to assign it a pointer to myView.

*Assuming this is a data-bearing object*, it is likely that you shouldn't be doing that:
<http://developer.apple.com/documentation/Cocoa/Conceptual/ CocoaFundamentals/CocoaDesignPatterns/chapter_5_section_4.html>


But when I put the '#import' statement in myObject's header file and declare a variable of type myView in myObject's header file and compile it, I get an error that says: error: parse error before "myObject" (which error is generated in the subclass of NSView). If I remove the #import statement and change the data type of the instance of myView to simply NSView (i.e. NSView *aView;), the project compiles just fine. Is there a problem with this circular referencing scenario that the compiler won't allow it?

It sounds like you need to use @class as a forward declaration:
<http://developer.apple.com/documentation/Cocoa/Conceptual/ ObjectiveC/Articles/chapter_4_section_5.html>
(then put the #import into your .m file).


mmalc

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Parent-Child References
      • From: Jason Barker <email@hidden>
References: 
 >Parent-Child References (From: Jason Barker <email@hidden>)

  • Prev by Date: Re: CoreData faulting - does it rely on #self?
  • Next by Date: Re: Parent-Child References
  • Previous by thread: Parent-Child References
  • Next by thread: Re: Parent-Child References
  • Index(es):
    • Date
    • Thread