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

The Archive Base Latest Questions

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

Wondering if there’s any accepted practice for approximating C++’s ‘const methods’ in Objective-C. (new

  • 0

Wondering if there’s any accepted practice for approximating C++’s ‘const methods’ in Objective-C. (new to the language from a C/C++ background)

For instance:

class Foo {
  public:
     void canChangeMemberVars(void);
     char* asString(void) const;
};

“asString()” gets a const this pointer, so even if you go rogue and decide to muck around with the instance’s members it won’t work. I find labelling methods as const to be quite useful from a documentation standpoint for libraries I write.

I’m in the midst of writing an Objective-C class library, and find myself wanting to be able to make specific methods const, and wondering if there’s any language tricks to achieve this.

Summarized:

At the end of the day is the the only way to achieve similar functionality to factor classes in Mutable and Immutable versions? Making a simple note in the comments for each method isn’t rigid enough for my purposes.

  • 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-17T16:21:31+00:00Added an answer on May 17, 2026 at 4:21 pm

    Yes, your only option if you want to have a class that sometimes can be mutated and sometimes can’t is to make mutable and immutable versions of the class. You’ll notice this is how Apple does it in Cocoa (NSArray, NSSet, NSDictionary, NSString, etc.) — following Apple’s conventions is usually the best way to go.

    Objective-C really doesn’t even have a concept of a const object. Even if you do declare an object pointer const, that doesn’t prevent you from calling methods on the object that set variables.

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

Sidebar

Related Questions

Wondering if there is any Text to Speech software available as a plug in
Wondering if there's any not-too-hard way to edit non-form text in html 4. I
Just wondering if there is any way (in C) to get the contents of
I was wondering if there are any alternatives to Microsoft's SQL Server Management Studio?
Wondering if there is any php script out there which takes an sql db
Wondering if there is any way to build and fire an event (e.g. on
I'm wondering if there's any way of having some sort of Aspect-Oriented way of
Wondering if there is a way to get the amount of rows returned from
Just wondering if there is an easy way to add the functionality to duplicate
was wondering if there are anyone else here that has signed up with the

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.