Document Architecture Problem
Document Architecture Problem
- Subject: Document Architecture Problem
- From: Tom Gray <email@hidden>
- Date: Tue, 16 Sep 2003 08:57:23 -0400
Hello,
Sorry to keep beating this dead horse, but, I am really confused. I am
having problems with the method initWithCoder in my NSDocument subclass.
I am using Oreilly's Building Cocoa Applications sample program
MathPaper sample code (available at
http://examples.oreilly.com/buildcocoa/index.html). I have modified
their code by adding NSLogs and one instance variable in the NSDocument.
Here is my problem: When I open a saved file the documents init is
called and an instance of the document (self) is created, next
loadDataRepresentation is called then initWithCoder is called. During
the method initWithCoder self changes! After initWithCoder self returns
to the original instance and execution continues. Any variable
assignments made during initWithCoder are unavailable!
In this case I simply assigned:
testString = @"Test String";
to the instance variable during initWithCoder. I verified its existence
with:
NSLog(@"testString is: %@", testString);
MathPaper[480] testString is: Test String
However, as soon as I returned from initWithCoder self returns to the
original instance and the variable is now null!
MathPaper[480] testString is: (null)
Here is the complete log of the process:
MathPaper[480] Init self: <MathDocument: 0x14b2540> <---- created object
MathPaper[480] loadDataRepresentation self: <MathDocument: 0x14b2540>
<--- still the same object
MathPaper[480] initWithCoder self: <MathDocument: 0x15276b0> <--- the
object has changed!
MathPaper[480] testString is: Test String <-- my documents instance
variable exists in the second object
MathPaper[480] windowNibName self: <MathDocument: 0x14b2540> <--- out
of initWithCoder the object resets
MathPaper[480] windowDidLoad self: <PaperController: 0x152b3b0>
MathPaper[480] makeWindowControllers self: <MathDocument: 0x14b2540>
<--- the first object
MathPaper[480] testString is: (null) <--- and my instance variable has
gone away!
As a result any decoding that is done in my initWithCoder is simply not
available! Effectively, I can't read my data from disk!
Perhaps the example I am using is incorrect.
I am not as concerned about solving this problem so much as creating a
workable document/controller application. Perhaps someone can point me
(an obviously clueless programmer) at some sample code that works.
Thanks
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.