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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:30:23+00:00 2026-05-26T16:30:23+00:00

I have been trying to add an object as an NSMutableDictionary to my array,

  • 0

I have been trying to add an object as an NSMutableDictionary to my array, which I am accessing from another view, and It doesn’t seem to work. I want to be able to store the data in a plist which I access from a NSDictionary.

-(void)saveAlarm:(id)sender {

    // Adding object for alarm to AlarmViewController

    alarmArrayCopy = alarmViewController.alarmsTime;

    NSMutableDictionary *newAlarm =  [[NSMutableDictionary alloc] init];
    [newAlarm setValue:labelTextField.text forKey:LABEL_KEY];
    [newAlarm setValue:alarmPicker.date forKey:TIME_KEY];
    [alarmArrayCopy addObject:(newAlarm)];

    // Dismissing and tiding up.

    [self.navigationController dismissModalViewControllerAnimated:YES];
    [newAlarm release];
}

UPDATE: How do I add an NSDictionary to my plist database (my db is an array)?

Here is some new code, I updated the NSMutableDictionary to NSDictionary because in my plist you can only have normal dictionaries not a mutable one. But now it crashed and gives me a Thread 1:Program received signal: "SIGABRT".

NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"data.plist"];

// Adding object for alarm to AlarmViewController

NSDictionary *newAlarm =  [[NSDictionary alloc] init];
[newAlarm setValue:labelTextField.text forKey:LABEL_KEY];
[newAlarm setValue:[NSString stringWithFormat:@"%@", alarmPicker.date] forKey:TIME_KEY];
[newAlarm writeToFile:finalPath atomically:NO];

or

-(IBAction)saveAlarm:(id)sender {

// Adding object for alarm to AlarmViewController

NSString *time = [NSString stringWithFormat:@"%@", alarmPicker.date];
NSString *label = [NSString stringWithFormat:@"%@",labelTextField.text];

NSDictionary *newAlarm = [[NSDictionary alloc] initWithObjectsAndKeys:label, LABEL_KEY,time, TIME_KEY, nil];
self.alarmArrayCopy = alarmViewController.alarmsTime;
[alarmArrayCopy addObject:(newAlarm)];

// Dismissing and tiding up.
[newAlarm release];
[self.navigationController dismissModalViewControllerAnimated:YES];

}

  • 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-26T16:30:24+00:00Added an answer on May 26, 2026 at 4:30 pm

    First, you should use setObject:forKey: method for adding objects to NSMutableDictionary. Second, you should use initWithObjectsAndKeys: method if you are using NSDictionary.

    The setValue:forKey is a method of the Key Value Coding protocol. That was described at here “
    Where's the difference between setObject:forKey: and setValue:forKey: in NSMutableDictionary?
    ”

    So, you should do that,

    NSDictionary *newAlarm = [[NSDictionary alloc] initWithObjectsAndKeys:
                                                   labelTextField.text, LABEL_KEY,
                                                   alarmPicker.date, TIME_KEY, nil];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to add to the Watch window a Java Date object
I'm trying to add a set of objects that have been retrieved from a
At www.euroworker.no/order I have been trying to add a tooltip function but it seems
I have been trying to learn how to add testing to existing code --
I want to add a thumbnail picture viewer to my application.I have been trying
I have been trying to work my way through Project Euler, and have noticed
I've been trying to add Facebook Connect to a website, but it didn't seem
I've been trying to somehow get my javascript function (which I have in the
I have been trying to use the comments.add REST api method to add comments
I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,

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.