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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:07:22+00:00 2026-05-26T22:07:22+00:00

Let me describe my problem first. I have a class which holds a NSMutableDictionary

  • 0

Let me describe my problem first. I have a class which holds a NSMutableDictionary ivar. There is a thread that will add new pairs into this dictionary – at the moment of writing the application I’m not able to have a full list of available keys. An up-to-date list of all this pairs have to be shown in the Table View.
I’ve prepared small proof of concept application where there is a Dictionary Controller created in the xib file, and its content is binded with the dictionary ivar. The problem is that Table View shows only initial set of the dictionary’s content. After insertion it’s not refreshed.

In my proof of concept application AppController.h is as follows:

#import <Foundation/Foundation.h>

@interface AppController : NSObject

@property (strong) NSMutableDictionary *dictionary;

- (NSString *)randomString;
- (IBAction)addRandomPair:(id)sender;

@end

And the implementation file content:

#import "AppController.h"

@implementation AppController

@synthesize dictionary = _dictionary;

- (id)init {
    self = [super init];
    if (self) {
        _dictionary = [[NSMutableDictionary alloc] init];
        [_dictionary setValue:@"Aa" forKey:@"A"];
        [_dictionary setValue:@"Bb" forKey:@"B"];
    }
    return self;
}

- (NSString *)randomString
{
    NSMutableString *aString = [[NSMutableString alloc] init];
    for (int i = 0; i < 3; i++) {
        NSUInteger r = random() % ('z' - 'a');
        [aString appendString:[NSString stringWithFormat:@"%c", ('a' +r)]];
    }
    return aString;
}

- (IBAction)addRandomPair:(id)sender
{
    [self.dictionary setValue:[self randomString] forKey:[self randomString]];
    NSLog([self.dictionary description]);
}

@end

Dictionary Controller Content is bound to the App Controller with Model Key Path set to “self.dictionary” and columns content in the Table View is bound to Dictionary Controller with Model Key Path set to key and value accordingly. In this proof of concept application button click adds a new pair (addRandomPair: action).

I had a similar problem with a NSMutableArray and Array Controller, but there I was able to solve the problem by adding following pair of methods to the class holding an array ivar (named data in this class):

- (void)insertObject:(NSString *)object inDataAtIndex:(NSUInteger)index;
- (void)removeObjectFromDataAtIndex:(NSUInteger)index;

Is it possible to add some other methods to the class holding a dictionary (AppController) to be notified about new insertions? Or maybe there is a better solution for my problem?

Update

I’ve found out that implementing following set of accessors makes Dictionary Controller notified about new item:

- (void)addDictionaryObject:(NSString *)object;
- (void)removeDictionaryObject:(NSString *)object;

The problem is that addDictionaryObject: has only one argument, dictionary would require something like addDictionaryObject:forKey:. Any ideas?

Update 2

I don’t see any other solution than using manual change notification – in this case addRandomPair: method looks like this:

- (IBAction)addRandomPair:(id)sender
{
    [self willChangeValueForKey:@"dictionary"];
    [self.dictionary setValue:[self randomString] forKey:[self randomString]];
    [self didChangeValueForKey:@"dictionary"];
    NSLog([self.dictionary description]);
}

It works, but I’m still a bit uncertain since dictionary itself will not change, but its content. Is using manual change notification a correct approach here?

  • 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-26T22:07:23+00:00Added an answer on May 26, 2026 at 10:07 pm

    From the Key-Value Coding methods document, only NSMutableArray or NSMutableSet is supported for To-Many properties. Since, KVC already works with keys, it would be redundant to have NSMutableDictionary supported since it’s effectively what setValue:forKey: already does.

    Maybe override setValue:forKeyPath: if you really want this in one call.

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

Sidebar

Related Questions

Let me first describe my situation. I have a list of Hex values, which
I've got a strange problem. Let me first describe my situation: Webserver01 (Webapplication, SQL,
Let me first describe my goal: I have created an object with 3 properties:
Let's say you have a class called Customer, which contains the following fields: UserName
I will first describe the problem and then what I currently look at, in
To describe my dilemma, let me first start with an example problem (stolen from
Let me describe the problem and the solution i currently have and maybe you
Let me try to explain what I need. I have a server that is
Here's the problem. In my app, I have 5 tabs which contains activities. In
Let me describe the problem in details: I want to show an absolute positioned

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.