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 749419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:25:57+00:00 2026-05-14T14:25:57+00:00

I’m making an app where I need to save the text in multiple views

  • 0

I’m making an app where I need to save the text in multiple views in the app when the app quits. I also need to be able to remove all of the data from just one of those views and when the app quits, it’s possible not all of those views will have been created yet.

After reading this post I thought perhaps it would be good to use a singleton that manages my app data which loads in the data when it is first requested and saved it when the app quits. Then in each view where I need to save data I can just set it on the singleton.

I gave it a go but have run into some issues. At first I didn’t synthesize the properties (as in the post I was using as a guide) but the compiler told me I needed to make getters and setters, so I did. Now when my applicationWIllTerminate: gets call the app crashes and the console says “Program received signal: “EXC_BAD_ACCESS”. kill quit”.

Is anyone able to tell me what I’m doing wrong, or suggest a better approach to saving the data?

//SavedData.h

#import <Foundation/Foundation.h>

#define kFileName @"appData.plist"

@interface SavedData : NSObject {
    NSString *information;
    NSString *name;
    NSString *email;
    NSString *phone;
    NSString *mobile;
}

@property(assign) NSString *information;
@property(assign) NSString *name;
@property(assign) NSString *email;
@property(assign) NSString *phone;
@property(assign) NSString *mobile;

+ (SavedData *)singleton;

+ (NSString *)dataFilePath;
+ (void)applicationWillTerminate:(NSNotification *)notification;
@end

//SavedData.m

#import "SavedData.h"

@implementation SavedData

@synthesize information;
@synthesize name;
@synthesize email;
@synthesize phone;
@synthesize mobile;

static SavedData * SavedData_Singleton = nil;

+ (SavedData *)singleton{

    if (nil == SavedData_Singleton){
        SavedData_Singleton = [[SavedData_Singleton alloc] init];

        NSString *filePath = [self dataFilePath];
        if([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
            NSMutableArray * array = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
            information = [array objectAtIndex:0];
            name = [array objectAtIndex:1];
            email = [array objectAtIndex:2];
            phone = [array objectAtIndex:3];
            mobile = [array objectAtIndex:4];           
            [array release];
        }
        UIApplication *app = [UIApplication sharedApplication];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:app]; 
    }
    return SavedData_Singleton;
}

+ (NSString *)dataFilePath{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *DocumentsDirectory = [paths objectAtIndex:0];
    return [DocumentsDirectory stringByAppendingPathComponent:kFileName];
}

+ (void)applicationWillTerminate:(NSNotification *)notification{
    NSLog(@"Application will terminate received");
    NSMutableArray *array = [[NSMutableArray alloc] init];
    [array addObject:information];
    [array addObject:name];
    [array addObject:email];
    [array addObject:phone];
    [array addObject:mobile];
    [array writeToFile:[self dataFilePath] atomically:YES];
    [array release];
}

@end

Then when I want to use it I do

myLabel.text = [SavedData singleton].information;

And when I change the field

[SavedData singleton].information = @"my string";

Any help will be very much appreciated!

  • 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-14T14:25:58+00:00Added an answer on May 14, 2026 at 2:25 pm

    You might want to change your properties to be (retain) instead of assign.

    You might want to get the singleton header file I use. It is quite nice for me.

    What is likely happening is that you load up your array from a file, and assign it to the property. But it is being autoreleased, and thus it doesn’t exist anymore. So when you try to access the memory later, it crashes.

    Further reading on memory management: http://www.cocoadev.com/index.pl?MemoryManagement

    • 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.