Identical names for methods and properties

cocoa, objective-c, properties

Solution

It could be a little confusing.

The property generates 2 instance methods for you:

- (NSCursor *)rotateCursor;
- (void)setRotateCursor:(NSCursor *)rotateCursor;

And you also have a class method:

+ (NSCursor *)rotateCursor;

It isn't clear from a user point of view what the class method does. Documentation would help.

Problem

The following code compiles just fine - but are there any issues with it? I couldn't find any guidelines for Objective-C that would discourage us from using the same identifier for both, properties and method names: ``` @interface MouseCursorHelper : NSObject @property (nonatomic, readwrite, retain) NSCursor* rotateCursor; + (NSCursor*) rotateCursor; @end ``` FWIW, the class is implemented as a singleton modeled after `NSCursor` to offer app specific cursors.

Original source