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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:38:04+00:00 2026-06-05T04:38:04+00:00

I have an NSMutableArray which contains a list of numbers taken from a textfield.

  • 0

I have an NSMutableArray which contains a list of numbers taken from a textfield.

Im trying to use the tapping of the done button to instigate saving the NSMutableArray in a plist within the NSuserdomain. To check the contents of the plist, im trying to reload them into another NSMUtableArray, and then print the array.

-(NSString *) dataFilePath
{ NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentDirectory = [path objectAtIndex:0]; return     [documentDirectory stringByAppendingPathComponent:@"WeightsList.plist"];
}

- (void)writePlist
{
    [weightsArray writeToFile:[self dataFilePath] atomically:YES];
}

-(void)readPlist
{ 
    NSString *filePath = [self dataFilePath]; 
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) 
    { 
        NSMutableArray *weightsArray = [[NSMutableArray alloc] initWithContentsOfFile:filePath]; 
    NSLog(@"%@\n",weightsArray); 
    NSLog(@"%@\n", filePath); 
   }
}

The “Done” action below, is what is called when the done button is pressed:

-(IBAction)done
{
int arrayCount;

id arrayVariable;

arrayCount = [weightsArray count];
[weightsArray addObject:weightInput.text];
arrayVariable = [weightsArray objectAtIndex:arrayCount];
NSLog(@"Weight Entered: %@", arrayVariable);
NSLog(@"%@",weightsArray);
[self writePlist];
[self readPlist];

[self dismissViewControllerAnimated:YES completion:nil];

}

My issue, is that the output is everytime:

2012-05-31 18:35:05.378 WeighMe[780:f803] /Users/jb/Library/Application Support/iPhone     Simulator/5.1/Applications/BE9D2906-50FA-4850-B3A5-47B454601F61/Documents/WeightsList.plist
2012-05-31 18:35:05.829 WeighMe[780:f803] Weight Entered: (null)
2012-05-31 18:35:05.830 WeighMe[780:f803] (null)
2012-05-31 18:35:05.831 WeighMe[780:f803] (
32432
)

Is this an issue with the plist not working correctly, or is it the NSMutableArray which isn’t getting the required data.

I’ve tried stepping through the runtime with the debugger, but tbh i dont really know how to use it properly.

Any help would be awesome! Thanks folks.

  • 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-05T04:38:07+00:00Added an answer on June 5, 2026 at 4:38 am

    You are redeclaring the array in the -(void) readPlist method:

    NSMutableArray *weightsArray = [[NSMutableArray alloc] initWithContentsOfFile:filePath]; 
    

    That line should be:

    weightsArray = [[NSMutableArray alloc] initWithContentsOfFile:filePath]; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Essentially I have an NSMutableArray which contains several NSDictionaries . I wish to sort
I have a Singleton which has an NSMutableArray containing a Class, the Class contains
I have a NSMutableArray: NSMutableArray *temp = //get list from somewhere. Now there is
I have a NSMutableArray which contains a few NSString objects. How can I test
Please help me i have a NSMutableArray which contains data until viewDidLoad is finished.
I have an NSMutableArray instance which contains N number of objects and I want
I have a NSMutableArray walkArray which contains another array walkSteps. I want to create
I have a very simple class called Profile. It contains NSMutableArray called avatar which
I have NSMutableArray which contains NSObjects. Each NSObject contains a NSString as property which
I have an NSMutableArray called myObjectArray which contains and array of NSObjects called myObject.

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.