Re: Simplifying this code?
Re: Simplifying this code?
- Subject: Re: Simplifying this code?
- From: Shawn Erickson <email@hidden>
- Date: Tue, 27 Jul 2004 08:13:20 -0700
On Jul 27, 2004, at 7:34 AM, Theodore H. Smith wrote:
I find it all very confusing, to be honest. Dearchiving creates a new
object?
Archiving creates and archive - a freeze dried snap shot - of an
existing object. The reverse of that is dearchiving.
What if I just want to restore values into an existing object?
Lets say I do this:
V *MyQuartzView; // Assume this exists.
result = [NSKeyedArchiver archiveRootObject:V
toFile:@"/tmp/FractalArchive"];
Now, will that work if MyQuartzView is defined like this?
@interface MyQuartzView : NSView {
IBOutlet NSColorWell *ColorWell;
IBOutlet NSTextField *CutField;
IBOutlet NSProgressIndicator *MyProgress; // this one I don't want
saved!
IBOutlet NSButton *TurnsSwitch;
....
MyRect* Rect;
}
Will it automatically store all IBOutlets? Or will it automatically
store everything including MyRect? In fact, if I had gone and used my
own archiver I could have done this already, because my design is much
simpler to explain. But I'm just trying to learn some Cocoa here :o)
It is rather unusual to store a view like this yourself. What you more
often do is define the code for such custom views and then have IB read
in that header and then assign a custom view object in a window/panel
to you custom view class. This results in your custom class being
hooked up and loaded in place when the nib is loaded and the view
structure constructed from what the nib defines (archived objects are
dearchived basically).
The question you need to ask yourself is what data do you need to store
and why? I doubt you need to save the view but simply the state of some
of the view elements. What is the state you need saved related to
"MyProgress".
Finally in Cocoa applications you usually follow a MVC paradigm (model
- view - controller). So your views shouldn't be containing the
state/model data... your model should hold this and that is what you
should be looking at archiving for storage in a file or possibly user
defaults. The following page contains information on MVC, etc.
<
http://developer.apple.com/documentation/Cocoa/Conceptual/
AppArchitecture/index.html>
One more thing... review the following document for the recommend
naming conventions for ivars, methods, etc. They are outlined to help
insure that consistent looking, naming, etc. are used to help in code
sharing with folks, etc.
<
http://developer.apple.com/documentation/Cocoa/Conceptual/
CodingGuidelines/index.html>
-Shawn
_______________________________________________
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.