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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:30:19+00:00 2026-05-17T23:30:19+00:00

I am trying to save and read back some application settings stored as NSStrings

  • 0

I am trying to save and read back some application settings stored as NSStrings in an iPhone app and have been having some trouble.

The code to save looks like:

    NSMutableArray *array = [[NSMutableArray alloc] init];
   [array addObject:accountID];
    ...
   [array writeToFile:[self dataFilePath] atomically:YES];
   [array release];

And the code to read looks like (accountID is an NSString*):

    NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];         
    accountID = [array objectAtIndex:0];
    ...                     
    [array release];
    NSLog(@"Loading settings for: %@", accountID);

The read code throws an exception because after the array is released the accountID variable also appears to have been released (moving the NSLog call before releasing the array works fine). So I’m guessing that I’m creating a reference to the array instead of pulling out the actual string contained in the array. I tried several things to create new strings using the array contents but haven’t had any luck.

  • 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-17T23:30:19+00:00Added an answer on May 17, 2026 at 11:30 pm

    You guess is on the right lines although you have a reference to the 0th element of the array not the array. The array consists of pointers to NSString objects. The Strings will get get released when yhe array is released.

    You need to retain the element you are using e/g/

    NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];         
    NSString* accountID = [[array objectAtIndex:0]retain];
    ...                     
    [array release];
    NSLog(@"Loading settings for: %@", accountID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to save some XML-Data in my UserSettings (Properties.Settings.Default.UserSettings) in a .NET Winforms
I have an asp.net app and I am trying to save a text file
I'm trying to write a simple integration test, but having some trouble with Domain
I'm trying to implement a Load / Save function for a Windows Forms application.
I'm implementing a stack-based VM and I've been trying to read up on literature
I am trying to do some databinding magic. I have a Shipments view that
I'm trying to save a binary file stored in a SQL database with a
I'm trying to implement User Registration for my Django app. The book I read
In my application I save voxel-data (compressed byte array) and trying to load it
When trying to save an uploaded file, I get this error and are having

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.