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.