• 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
Re: A problem of NSUserdefaults
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A problem of NSUserdefaults


  • Subject: Re: A problem of NSUserdefaults
  • From: Yorh <email@hidden>
  • Date: Thu, 13 Jul 2006 19:00:46 +0200

Do you quit the appliocation using xcode button or by command q?
Because the prefs are saved only when the application receive the termination message....


bye
Yorh
On 13/lug/06, at 18:48, Bus Mini wrote:

Hi all,

I have run into a problem when using NSUserdefaults. That is, I did change
the value of NSUserDefaults ,but the next time I run my application, the
preferences is the old one. Followed is my code, could any one help me find
my problem? Thanks very much.




@interface MyObject : NSObject
{
   IBOutlet id myOutlet1;
   IBOutlet id myOutlet2;
   IBOutlet id myOutlet3;
   IBOutlet id myOutlet4;
NSUserDefaults * prefs;

}
- (IBAction)save:(id)sender;
@end

#import "MyObject.h"

@implementation MyObject

- (IBAction)save:(id)sender
{

       [prefs setObject:[myOutlet1 stringValue] forKey:@"FavBook"];

       [prefs setObject:[myOutlet1 stringValue] forKey:@"FavCity"];

       [prefs setObject:[myOutlet1 stringValue] forKey:@"FavColor"];

       [prefs setObject:[myOutlet1 stringValue] forKey:@"FavFood"];
}


- (id)init { [super init]; NSMutableDictionary * defaultPrefs = [NSMutableDictionary dictionary]; [defaultPrefs setObject:@"Learning Cocoa" forKey:@"FavBook"]; [defaultPrefs setObject:@"San Francisco" forKey:@"FavCity"]; [defaultPrefs setObject:@"Red" forKey:@"FavColor"]; [defaultPrefs setObject:@"Mexican" forKey:@"FavFood"];

   prefs = [[NSUserDefaults standardUserDefaults]
retain];
   [prefs
registerDefaults:defaultPrefs];
   return self;
}

- (void)dealloc
{
   [prefs release];
   [super dealloc];
}


- (void)awakeFromNib { [myOutlet1 setStringValue:[prefs stringForKey:@"FavBook"]]; [myOutlet2 setStringValue:[prefs stringForKey:@"FavCity"]]; [myOutlet3 setStringValue:[prefs stringForKey:@"FavColor"]]; [myOutlet4 setStringValue:[prefs stringForKey:@"FavFood"]]; }



@end


--
Yours sincerely
Mini Bus.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40metagraphics.it


This email sent to email@hidden

_______________________________________________ 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
References: 
 >A problem of NSUserdefaults (From: "Bus Mini" <email@hidden>)

  • Prev by Date: Re: Weird tabbing results
  • Next by Date: Re: A problem of NSUserdefaults
  • Previous by thread: Re: A problem of NSUserdefaults
  • Next by thread: Re: A problem of NSUserdefaults
  • Index(es):
    • Date
    • Thread