Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a readonly BOOL property. What is dominant naming pattern here?

Background: for plain old method declarations, the accepted pattern

- (BOOL)isEditable;
- (void)setEditable:(BOOL)flag;

In a @property world, that would typically be expressed as

@property(getter=isEditable) BOOL editable;

However, there are examples to the contrary. Such as in CalStore/CalCalendar.h

@property(readonly) BOOL isEditable;

(Is CalCalendar wrong here, or is that the also an acceptable naming pattern for read-only BOOL properties?)

I've got a controller which manages a view, which may or may not be resizable. The property is read only.

@property(readonly) BOOL viewIsResizable;
@property(readonly) BOOL isViewResizable;
@property(readonly, getter=isViewResizable) BOOL viewResizable;

Which pattern is most natural or Cocoa-like?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
745 views
Welcome To Ask or Share your Answers For Others

1 Answer

quoted from ADC

If the attribute is expressed as an adjective, the format is:

- (void)setAdjective:(BOOL)flag;
- (BOOL)isAdjective;

For example:

- (void)setEditable:(BOOL)flag;
- (BOOL)isEditable; 

If the attribute is expressed as a verb, the format is:

- (void)setVerbObject:(BOOL)flag; 
- (BOOL)verbObject;

For example:

- (void)setShowsAlpha:(BOOL)flag;
- (BOOL)showsAlpha; 

The verb should be in the simple present tense.

|K<


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...