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

  • SEARCH
  • Home
  • 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 8775445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:48:01+00:00 2026-06-13T18:48:01+00:00

I am encountering a confusing problem in my Objective-C program. I am trying to

  • 0

I am encountering a confusing problem in my Objective-C program. I am trying to save data from an NSMutableArray when my program enters the background. I have a static variable called savedResults in my AppDelegate. A view controller manipulates this variable and adds data to it during the lifetime of my program. I have an logical condition to check if savedResults is null, and if it isn’t then I need to save the data. Here is my code:

NSString *const kFileName = @"PCFData.bin";
//these are all my static variables..I have to initialize them to something so
//they can be used in other parts of my program with the keyword extern.
NSString *finalTermValue = @"";
NSString *finalClassValue = @"";
NSString *finalTermDescription = @"";
NSMutableArray *savedResults = nil;

@implementation PCFAppDelegate

@synthesize finalTermValue, finalClassValue, finalTermDescription, savedResults;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDir = [paths objectAtIndex:0];
    NSString *fullPath = [docDir stringByAppendingFormat:@"/%@", kFileName];
    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:fullPath];
    if (fileExists) {
        savedResults = [NSKeyedUnarchiver unarchiveObjectWithFile:fullPath];
    }
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    if (savedResults) {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSUserDirectory, NSUserDomainMask, YES);
        NSString *docDir = [paths objectAtIndex:0];
        NSString *fullPath = [docDir stringByAppendingFormat:@"/%@", kFileName];
        [NSKeyedArchiver archiveRootObject:savedResults toFile:fullPath];
    }
}

I put a breakpoint in the applicationDidEnterBackgroundMethod to see what is going on. My program never enters the block of code inside the if statement, even though the savedResults array is NOT null. I have also tried testing if ([savedResults count] > 0) and it does not enter the block even though it is greater than zero. Here is a picture of the variables XCode is showing. As you can see, there ARE objects in the array.
bug
bug2
I have a feeling XCode is looking at the array declaration above where I set it to nil instead of the actual variable. How do I distinguish these two? Any help would be greatly appreciated. Thanks!

  • 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-06-13T18:48:03+00:00Added an answer on June 13, 2026 at 6:48 pm

    You have two variables named savedResults. One is a global variable. The other is an instance variable in the PCFAppDelegate class, generated by the @synthesize savedResults statement. The debugger showing you both variables. The instance variable is under the expansion of self and the global variable is shown to the right of a disclosure triangle and an “S” in a red box.

    All of the mentions of savedResults in methods of PCFAppDelegate use the instance variable, but mentions in other classes will use the global variable. So some code outside of PCFAppDelegate is setting the global variable to non-nil, but in
    -[PCFAppDelegate applicationDidEnterBackground]`, you can only access the instance variable, which is still set to nil.

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

Sidebar

Related Questions

I am encountering a problem with passing data between pages that require facebook access.
I´m encountering this problem trying to mock some objects that receive complex lambda expressions
I'm encountering the following problem - I have simple GWT overlay types, and I'm
recently I have been encountering problems with exposing events from .NET to COM. I
I am encountering a bug-like problem in Opera when trying the get the closed
Ive been encountering this problem since I last upgraded PhoneGap from 1.3.0 to 1.4.1,
I'm encountering a problem generating my client and server code from wsdl. I've been
I am encountering a problem while extracting info from a database using php+mysql and
I am encountering a problem which I have never encountered before. I am working
I'm encountering a problem with my WP7 app: I'm trying to make a login

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.