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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:12:17+00:00 2026-05-27T00:12:17+00:00

I am having the following code: @interface Room : NSObject { @protected NSMutableDictionary* mCustomProperties;

  • 0

I am having the following code:

@interface Room : NSObject
{
@protected
    NSMutableDictionary* mCustomProperties;
}

@property (readonly, copy) NSDictionary* CustomProperties;

@end



@interface MutableRoom : Room
{
}

@property (readwrite, retain) NSMutableDictionary* CustomProperties;

@end

These properties are then implemented later by accessing mCustomProperties.
I know, that it is not allowed to redeclare the memory management attribute or the data type of a property in a subclass to differ from the ones in the base class.
However, I want to achieve the following:
– Give only readonly access to the dictionary in the immutable base class. As the member is a NSMutableDictionary, just returning it as a retained instance of NSDictionary would mean, that it simple cast would make it mutable again, even unintended, when the user of the property stores the access variable somewhere as an NSObject instance and then recovers the original type of it back later. Therefor I want to return the mutable dictionary by immutable copy in the readonly property.
– Give full readwrite access to the dictionary in the mutable sub class. As you should not only be able to store another dictionary there, but also to just change the content of the existing one, I would like the property in the subclass not only to be readwrite, but also to be retained, instead of copied, so that the original values will be accessed, and to access it as an NSMutableDictionary, not as a NSDictionary, so that one can add, remove or change entries of the dictionary through the property.

Is there any more elegant way than suppressing the warning or using two differently named properties?

  • 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-27T00:12:18+00:00Added an answer on May 27, 2026 at 12:12 am

    when declaring a mutable/immutable pair of a class cluster, i often find it simplest to not inherit from another, but to use an inner class for the implementation, like so:

    // Room.h
    @interface Room : NSObject
    // ...
    @end
    
    @interface MutableRoom : Room
    // ...
    @end
    
    // MONRoom.h
    @class RoomImp;
    
    @interface MONRoom : Room
    {
    @private
        RoomImp * imp;
    }
    
    @property (readonly, copy) NSDictionary* CustomProperties;
    
    @end
    
    @interface MONMutableRoom : MutableRoom
    {
    @private
        RoomImp * imp;
    }
    
    @property (readwrite, retain) NSMutableDictionary* CustomProperties;
    
    @end
    
    // RoomImp.h
    @interface RoomImp : NSObject
    {
    @private
        NSMutableDictionary* mCustomProperties;
    }
    
    // ...
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I m having the following code, however, I can see that the radio button
I am having following peice of code ,where in i am trying to serialize
Having sorted the tag_counts hash via the following code: sorted_tags = Contact.tag_counts.sort{ |x,y| x.name.downcase
I'm having an issue with the following code: private void DataPortal_Fetch(TaskCriteria criteria) { using
I'm having some problems with the following code: private class ClientPluginLoader : MarshalByRefObject {
I'm having troubles with the following code: <link type=text/css href=http://jqueryui.com/latest/themes/base/jquery.ui.all.css rel=stylesheet /> <script type=text/javascript
I'm having an ArrayIndexOutofBounds exception with the following code. The exception is thrown at
I'm having a hard time understanding why the following code doesn't work. I'm sure
I have the following code: SELECT <column>, count(*) FROM <table> GROUP BY <column> HAVING
I'm having a problem getting a change event to register with the following code:

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.