Re: Correct Time to Write Extra code on Shutdown
Re: Correct Time to Write Extra code on Shutdown
- Subject: Re: Correct Time to Write Extra code on Shutdown
- From: Ondra Cada <email@hidden>
- Date: Fri, 28 Apr 2006 23:20:34 +0200
Jerrod,
On 28.4.2006, at 23:06, Jerrod Fowkes wrote:
I have an application that loads some information from a file on
startup, and needs to write to a file on startup.
the last word, presumably, should have been "shutdown"?
... Well, currently I load the information in the 'init' of my
ApplicationController. Is this the correct and optimal way of doing
things? Maybe it should be awakeFromNib?
Depends. If you load it from NIB, awakeFromNib is better for in that
case, you may not get init at all (the ways of how NIBbed objects are
initialized are somewhat complex, and better just to dodge inits for
NIBbed objects if possible).
There might be a point in waiting till the app finishes loading (see
app delegate methods). Or, contrariwise, you may need to read the
data ASAP, perhaps in +initialize. Depends on the actual code and task.
Also I need the optimal way of storing the data before the
application shuts down. I am currently throwing around the idea of
doing this in the dealloc.
Forget it, the idea is truly throwable :) Scan the archives to know
why :)
From a coding / engineering / cocoa application specialist
perspective, is this the most horrible way or the most feasible?
Actually, the best way is to put the data out *not* at shutdown, but
whenever they change (with the obvious optimisation that if they are
changing often, you may wait for, say, a minute without any change
before you save). If the app happens to crash then (or be killed, or
power goes down, or whatever), the user won't lose all the set up.
If this is not feasible for some reason, check again the application
delegate methods :)
... These sorts of things I don't think you can really get from
books or documentation ...
A lot of them, actually, are documented quite well.
As I've written umpteen times, do find the time to sift through the
Cocoa docs. It is obviously not feasible to read the complete stuff
religiously, but it is **well worth** the time just to scan through,
reading at least the intro paragraph of each class or protocol, to
get a rough idea what is available and where it is.
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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