Re: Saving is so darn hard!
Re: Saving is so darn hard!
- Subject: Re: Saving is so darn hard!
- From: Charles Srstka <email@hidden>
- Date: Sun, 31 Mar 2002 21:20:04 -0600
RTFM NSBundle.
On Sunday, March 31, 2002, at 09:14 PM, deekpyro wrote:
I've found this function I want to use:
-(BOOL)copyPath:(NSString *)source toPath:(NSString *)destination
handler:handler
but I don't understand a few things. First I have to supply the
location of
the first file, but the location will change depending on where the user
puts my application folder. How would I tell it to take the file from
"files" under my application folder? Should I force the user to put
them
under the applications folder? Thanks...
on 3/31/02 6:07 PM, Charles Srstka at email@hidden wrote:
Most of the documentation you will need for the Cocoa classes will be
in
one of these two files:
/Developer/Documentation/Cocoa/Reference/Foundation/ObjC_classic/Foundation.
pdf
/Developer/Documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/AppKit.
pdf
The AppKit docs describe most of the classes that deal with the user
interface part of your program, such as menus, windows, buttons, etc.
while the Foundation docs describe the "behind-the-scenes" classes
dealing with things like strings, arrays, etc. The documentation for
NSFileManager can be found in the Foundation docs.
Charles
On Sunday, March 31, 2002, at 05:56 PM, deekpyro wrote:
I can't seem to find the documentation for it. Where is it?
Thanks
on 3/31/02 5:14 PM, Charles Srstka at email@hidden wrote:
Check the documentation on NSFileManager. It will tell you what you
need
to know.
On Sunday, March 31, 2002, at 05:03 PM, deekpyro wrote:
WOW! It works, thanks so much!
Now to figure out how to copy files...
Thanks, Derek
on 3/31/02 4:36 PM, Charles Srstka at email@hidden wrote:
On Sunday, March 31, 2002, at 04:20 PM, deekpyro wrote:
What I want to do is have it save the state of the checkbox so the
next
time
the app starts up it is at the state that it was when it was last
closed.
Any ideas?
Um, do exactly what you were doing, except don't set the preference
to
YES every time the application loads. In other words, leave out
what
you
were doing in the initialize method, and just do the stuff in the
windowDidLoad and the check box action.
One other thing is to make sure the windowDidLoad method actually
loads
when the program starts. I could be wrong, but I think that
windowDidLoad is a method of NSWindowController that you can only
override if you are a subclass of that class. You might want to try
awakeFromNib or applicationDidFinishLaunching: instead.
PS. I also want to know how to copy files in Cocoa
Thanks
on 3/31/02 4:05 PM, Charles Srstka at email@hidden wrote:
I dunno, it just looks to me like your initialize method is
setting
the
preference to YES every time you start up. I just get
[NSUserDefaults
standardUserDefaults] and get the preference from it without
worrying
about sending a dictionary to registerDefaults:. If what you're
trying
to do is have some default settings that are used the first time
the
app
is run, you might want to try something like this:
- (NSDictionary *)defaultValues
{
return [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES],STSCheckBoxKey,
/*the rest of your default settings go here*/,
nil];
}
- (id)getPreferenceForKey:(NSString *)key
{
id thePref;
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if (!(thePref = [prefs objectForKey:key]))
{
thePref = [[self defaultValues] objectForKey:key];
[prefs setObject:thePref forKey:key];
}
return thePref;
}
Then call [[self getPreferenceForKey:STSCheckBoxKey] boolValue]
in
your
code to get the state you need to set the check box to.
Charles
On Sunday, March 31, 2002, at 03:53 PM, deekpyro wrote:
Like what? (this is pretty much what my book told me to put for
+initialize
Thanks
on 3/31/02 3:17 PM, Charles Srstka at email@hidden wrote:
How about commenting out the stuff that's in +(void)initialize?
On Sunday, March 31, 2002, at 03:00 PM, deekpyro wrote:
Ok, I think I've got most of it, but it still doesn't work:
#import "Controller.h"
NSString *STSCheckBoxKey = @"WBC Enabled";
@implementation Controller
+ (void)initialize
{
// Create a dictionary
NSMutableDictionary *defaultValues = [NSMutableDictionary
dictionary];
// Put the values in the dictionary
[defaultValues setObject:[NSNumber numberWithBool:YES]
forKey:STSCheckBoxKey];
// Register the dictionary of defaults
[[NSUserDefaults standardUserDefaults] registerDefaults:
defaultValues];
NSLog(@"registered default: %@", defaultValues);
}
- (void)windowDidLoad
{
NSUserDefaults *defaults;
defaults = [NSUserDefaults standardUserDefaults];
[theCheckBoxWBC setState:[defaults
boolForKey:STSCheckBoxKey]];
}
// actions //
- (IBAction)theCheckBoxWBCClicked:(id)sender
{
[[NSUserDefaults standardUserDefaults] setBool:[sender state]
forKey:
STSCheckBoxKey];
}
What do you think?
on 3/31/02 1:11 PM, Charles Srstka at email@hidden wrote:
Read the documentation for NSUserDefaults and you will soon
be
saying,
"Saving is so darn easy!"
On Sunday, March 31, 2002, at 11:27 AM, deekpyro wrote:
I want to set up my program so that when it loads whatever
the
value
of
theCheckBox would be the same as when you closed it (hence
it
saves).
I've
been refering to multiple books but all of them just confuse
me. I
know
about the NSCoding protocal and to use NSArchiver and
NSUnarchiver,
but
those are the ones that get me. I know how to do
encodeWithCoder
and
initWithCoder but those NSArchivers and NSUnarchivers get
me.
Could
someone
PLEASE show me how to implement those for saving a simple
checkBox?
Thanks
so much!
_______________________________________________
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.
_______________________________________________
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.
_______________________________________________
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.