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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:20:42+00:00 2026-05-27T16:20:42+00:00

UPDATE: Figured out some stuff and changed code. When I add my NSDictionary to

  • 0

UPDATE: Figured out some stuff and changed code.

When I add my NSDictionary to my array it suddenly replaces the previous dictionary I added last time. I don’t know why this is happening. I am using a plist as data storage.

I get a error message like this:

Thread 1:Program received signal: “EXC_BAD_ACCESS”.

Init

-(id)init{
    self=[super init];
    if(self){
        dbArray = [[NSMutableArray alloc] init];
    }
    return self;
}

Adding a new item.

-(void)addNewItem:(NSString *)aString
{
    // Creates a mutable dictionary with a anonymous string under the NAME key.
    NSDictionary *newString = [[NSDictionary alloc] initWithObjectsAndKeys:aString,@"name", nil];

    // Adds the new string to empty dbArray.
    [dbArray addObject:(newString)];
    NSLog(@"[add]:Added anonymous string to dbArray, under name key.");

    // Writes the current dbArray (with the dict) to plist and releases retain counts.
    [self writeItem];
    [newString release];
}

My method to view my data.

-(void)viewData
{
    // View data from the created plist file in the Documents directory.

    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *finalPath = [documentsDirectory stringByAppendingPathComponent:@"data.plist"];

    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:finalPath]) {
        self.dbArray = [NSMutableArray arrayWithContentsOfFile:finalPath];
    }
    else {
        self.dbArray = [NSMutableArray array];
    }
}
  • 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-27T16:20:43+00:00Added an answer on May 27, 2026 at 4:20 pm

    instead this

    self.dbArray = [[NSMutableArray alloc] init];
    

    use this

    if( nil == self.dbArray ) {
      self.dbArray = [[NSMutableArray alloc] init];
    }
    

    UPDATE: (based on provided code)

    • you’re using different instances of DataObject class for displaying & saving data. Your content is over-written, because you don’t load data from file during initialization of each instance; to fix that fast, you need to implement init method of your DataObject class as below:
    - (id)init{
        self = [super init];
        if(self){
          [self viewData];
        }
        return self;
    }
    

    the following code from viewDidLoad of ViewController class will crash your application very often:

    db = [[DataObject alloc] init];
    [db viewData];
    [db release];
    
    array = [[NSMutableArray alloc] initWithArray:[db dbArray]];
    

    replace it with

    db = [[DataObject alloc] init];
    [db viewData];
    
    array = [[NSMutableArray alloc] initWithArray:[db dbArray]];
    

    call [db release] only in dealloc implementation

    • another problem, that you’ll probably arise – is updated data is not displayed when you’re back to the main screen; to fix that add the following method implementation to your ViewController.m file:
    - (void)viewWillAppear:(BOOL)animated
    {
      [super viewWillAppear:animated];
    
      [db viewData];
      self.array = [NSMutableArray arrayWithArray: db.dbArray];
      [self.tableView reloadData];
    }
    

    also in AddView.m replace the following code

    // Dismiss view and reload tableview.
    ViewController *vc = [[ViewController alloc] init];
    [self dismissModalViewControllerAnimated:YES];
    [vc release];
    

    with

    // Dismiss view and reload tableview.
    [self dismissModalViewControllerAnimated:YES];
    

    Just as advise: see more information about using delegates and passing object instances & copies between objects.

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

Sidebar

Related Questions

UPDATE: OK I figured it out, looks like fread has a filesize limitation, changed
Update II I Figured this out. When using google maps api, the model must
I'm trying to figure out a way to add a self-update feature to a
UPDATE OK, I figured it out. I had to call the following for varieties:
UPDATED: Added some sample code to help clarify. Hi, Feel like this shouldn't be
I am trying to figure out how I can update my sql query dynamically.
A puzzler from a coworker that I cannot figure out... update btd.dbo.tblpayroll set empname
I'm trying to do a simple update, but can't figure out somthing. I have
Update: Solved, with code I got it working, see my answer below for the
Update: Check out this follow-up question: Gem Update on Windows - is it broken?

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.