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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:30:01+00:00 2026-05-21T22:30:01+00:00

Suppose we have simple NSDictionary class, can one of its objects be an NSMutableDictionary

  • 0

Suppose we have simple NSDictionary class, can one of its objects be an NSMutableDictionary object? When we edit a value within the NSMutableDictionary object, we are only editing values of the object of NSDictionary. Since we are not editing the object of NSDictionary, should it be a problem for the non-mutable NSDictionary class?

  • 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-21T22:30:02+00:00Added an answer on May 21, 2026 at 10:30 pm

    The mutability of a collection class refers only to the ability to modify the collection as a whole, not the members. The collection in fact just consists of pointers to the objects it contains; nothing about them is changed. Putting an object inside an immutable collection does not change the object’s own ability to be modified.

    So, yes, you can modify an NSMutableDictionary inside an NSDictionary, without difficulty.

    NSDictionary * myDict;
    myDict = [NSDictionary dictionaryWithObject:
                [NSMutableDictionary dictionaryWithObject:@"This is one string"
                                                   forKey:@"sampleKey"]
                                         forKey:@"mutableDict"];
    
    NSMutableDictionary * myMutableDict = [myDict objectForKey:@"mutableDict"];
    
    NSLog(@"%@", [myMutableDict objectForKey:@"sampleKey"];
    // Prints "This is one string"
    
    [[myDict objectForKey:@"mutableDict"] setObject:@"Not the same as before" 
                                             forKey:@"sampleKey"];
    
    NSLog(@"%@", [myMutableDict objectForKey:@"sampleKey"];    
    // Prints "Not the same as before"
    

    Likewise for any object (which allows modification) contained inside any immutable collection:

    @interface MyNeatObjectClass : NSObject {
            NSString * neatString;
    }
    
    - (id)initWithNeatString:(NSString *)initialString;
    - (void)setNeatString:(NSString *)newString;
    - (NSString *)neatString;
    

    MyNeatObjectClass * myObj = [[MyNeatObjectClass alloc] 
                                             initWithNeatString:@"Example string"];
    
    NSLog(@"%@", [myObj neatString]);    // Prints "Example string"
    NSArray * arr = [NSArray arrayWithObject:myObj];
    [myObj release];
    
    // instance of MyNeatObjectClass
    [[arr objectAtIndex:0] setNeatString:@"Another string"];
    NSLog(@"%@", [[arr objectAtIndex:0] neatString]);     // Prints "Another string"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have simple class Order, that have a TotalPrice calculated property, which can
Suppose I have the following (trivially simple) base class: public class Simple { public
Suppose I have a simple program which takes argument input in one of the
Suppose i have one simple function in my program. Whenever i call that function
Suppose I have a simple class in Scala: class Simple { def doit(a: String):
Suppose you have a simple function, which can get quite expensive for large values:
Suppose I have a simple Java class like this: public class User { String
Suppose I have a simple class that Adds: public class Multiply { public int
Suppose I have simple class like: class MyClass { private $_prop; public function getProp()
Suppose, I have a simple type: public class Report { public Report() { BirthDate

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.