Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3228748
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:43:46+00:00 2026-05-17T16:43:46+00:00

I have declared some string properties on the app delegate for the purpose of

  • 0

I have declared some string properties on the app delegate for the purpose of global manipulation.

The trouble is the values that are written are not the same values that are being read. When I put debugging messages to print the values, it is familiar data. It almost looks like its being cached.

Code for declaration:

    //globals
    NSUserDefaults *options;
    NSString *strUserLogin;
    NSString *strTransKey;
    NSString *strBizName;
    NSString *strSwitchTesting;
    NSString *strDate;
    NSString *strTotalAmount;
    NSString *strTopMessage;
    NSString *strBottomMessage;
    NSString *strTransType;
    NSString *strMerchantName;
    NSString *strCustomerEmail;
    NSString *strMerchantEmail;

@property(nonatomic,retain) NSUserDefaults *options;
@property(nonatomic,retain) NSString *strUserLogin;
@property(nonatomic,retain) NSString *strTransKey;
@property(nonatomic,retain) NSString *strBizName;
@property(nonatomic,retain) NSString *strSwitchTesting;
@property(nonatomic,retain) NSString *strDate;
@property(nonatomic,retain) NSString *strTotalAmount;
@property(nonatomic,retain) NSString *strTopMessage;
@property(nonatomic,retain) NSString *strBottomMessage;
@property(nonatomic,retain) NSString *strTransType;
@property(nonatomic,retain) NSString *strMerchantName;
@property(nonatomic,retain) NSString *strCustomerEmail;
@property(nonatomic,retain) NSString *strMerchantEmail;

Load global variables with NSUserDefaults:

[NSUserDefaults resetStandardUserDefaults];
options = [NSUserDefaults standardUserDefaults];
if(options)
{
    strUserLogin = [options stringForKey:@"UserLogin"];
    strTransKey = [options stringForKey:@"TransKey"];
    strBizName = [options stringForKey:@"BizName"];     
    strSwitchTesting =[options stringForKey:@"SwitchTesting"];      
    //str date
    //total amount
    strTopMessage =[options stringForKey:@"MessageTop"];
    strBottomMessage =[options stringForKey:@"MessageBottom"];
    //trans type 
    strMerchantName = [options stringForKey:@"BizName"];
    //customer email
    strMerchantEmail =[options stringForKey:@"MerchantEmail"];
}
else {
    NSLog(@"applicationDidFinishLaunching: Error reading config file.");
}

Code to set global variables back to NSUserDefaults:

//save to disk preferences
    [options setObject: txtUserLogin.text forKey:@"UserLogin"];
    [options setObject: txtTransKey.text forKey:@"TransKey"];
    [options setObject: txtBizName.text forKey:@"BizName"];
    [options setObject: txtMerchantEmail.text forKey:@"MerchantEmail"];
    [options setObject:txtMsgTop.text forKey:@"MessageTop"];
    [options setObject:txtMsgBottom.text forKey:@"MessageBottom"];
    if(switchTesting.on)
    {
        [options setObject:@"ON" forKey:@"SwitchTesting"];
    }
    else 
    {
        [options setObject:@"OFF" forKey:@"SwitchTesting"];
    }

    //this is the magic sauce
    [options synchronize];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:43:47+00:00Added an answer on May 17, 2026 at 4:43 pm

    As you’re using ivars and not the properties you declared, I’m guessing your objects are getting released before you set them. However, as you’re not crashing it may be something else.

    Try this:

    [NSUserDefaults resetStandardUserDefaults];
    self.options = [NSUserDefaults standardUserDefaults];
    if(options)
    {
        self.strUserLogin = [options stringForKey:@"UserLogin"];
        self.strTransKey = [options stringForKey:@"TransKey"];
        self.strBizName = [options stringForKey:@"BizName"];     
        // You get the idea.
    }
    else {
        NSLog(@"applicationDidFinishLaunching: Error reading config file.");
    }
    

    and this

    [self.options setObject: txtUserLogin.text forKey:@"UserLogin"];
    [self.options setObject: txtTransKey.text forKey:@"TransKey"];
    [self.options setObject: txtBizName.text forKey:@"BizName"];
    [self.options setObject: txtMerchantEmail.text forKey:@"MerchantEmail"];
    // ...
    

    In general, if you declare a property, it’s a good idea to use the setters and getters when updating / reading the value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.