Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
759 views
in Technique[技术] by (71.8m points)

objective c - Naming conventions for BOOL Obj-C 2 properties?

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

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

1 Reply

0 votes
by (71.8m points)

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<


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...