Are there any disadvantages, if I were to replace all my accessors (get-like const methods) with readonly properties in Objective-C? Are they interchangeable?
I prefer readonly properties for documentation/readability.
Coming from C++, I am thinking of replacing all my const methods (non-mutable methods) with readonly properties in ObjC.
If I adhere to this convention, then I can automatically assume that any regular methods will be changing state (non-const method in C++). Also from a functional-programming perspective, knowing that a readonly property won’t change any state (having no side-effects) is useful.
Yes, they are interchangable.
is the same as
Although you won’t see it in your code, a property does create a myStr method that is accessible. In both cases, you could use
self.myStror[self myStr]to invoke the method.Side note: if you are using iOS 6 you do not need to include the @synthesize statement. Otherwise you would write:
@synthesize myStr = _myStr;in the implementation file.