[Solved] Class method access by dot operator [duplicate]


NSMutableString.string is a hack. It “works” for the same reason that myString.length and [myString length] produce the same result. However, since dot notation is not used with an actual property, it is an abuse of the language feature, because properties have a different semantic. For example, when you access a property multiple times, you naturally expect to get the same result, unless the state of the object has changed in between the two invocations. Since NSMutableString.string produces a new string object on each invocation, it breaks the semantic expected of the “proper” properties, bringing down the readability of your program.

Objective-C does not have a general way of calling a method with arguments using the dot notation. There feature is very specific to properties. Although theoretically you could use MyClass.xyz = abc in place of [MyClass setXyz:abc], but that would be a hack as well.

To answer your question, Objective-C does not offer a way to call [NSMutableString stringWithString:@"test"] with dot notation.

9

solved Class method access by dot operator [duplicate]