• 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
initWithCoder Confusion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

initWithCoder Confusion


  • Subject: initWithCoder Confusion
  • From: Tom Gray <email@hidden>
  • Date: Mon, 15 Sep 2003 16:37:02 -0400

Hello,

I have a simple document based application. My NSDocument subclass seems to be instantiating two different objects when it comes into existence following opening of a file. I use O'Reilly's Building Cocoa Applications "MathDocument" sample code as my sample code.

As in their sample, my NSDocument subclass has an init and an initWithCoder method. At the completion of the init the memory address of self is different then the memory address of initWithCoder. I have two instances of my document. The controller that uses this document points to the instance created with the init, unfortunately, my data is in the instance that came into existance with the initWithCoder.

Here is a log where I logged the method and the current memory value of self:

2003-09-15 16:25:05.694 Crewdog Terminal[2334] init self: <CDTextEditorDocument: 0x1476c40>
2003-09-15 16:25:05.872 Crewdog Terminal[2334] loadDataRepresentation self: <CDTextEditorDocument: 0x1476c40>
2003-09-15 16:25:05.873 Crewdog Terminal[2334] initWithCoder self: <CDTextEditorDocument: 0x12eb90>

2003-09-15 16:25:05.944 Crewdog Terminal[2334] makeWindowControllers self: <CDTextEditorDocument: 0x1476c40>
2003-09-15 16:25:05.945 Crewdog Terminal[2334] windowNibName self: <CDTextEditorDocument: 0x1476c40>

The NSDocument subclass init's and is at 0x147, next loadDataRepresentation is called, still with self at 0x147, then initWithCoder is called and self has changed to 0x12eb90. After exiting initWithCoders execution continues with makeWindowControllers and windowNibName but now self is back to 0x147.

What have I done?

Tom Gray
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: cocoa-dev digest, Vol 2 #2921 - 14 msgs
  • Next by Date: Re: Applescript in Cocoa - problem with custom command
  • Previous by thread: Re: cocoa-dev digest, Vol 2 #2921 - 14 msgs
  • Next by thread: Re: initWithCoder Confusion
  • Index(es):
    • Date
    • Thread