BOOL Obj-C 2属性的命名约定? [英] Naming conventions for BOOL Obj-C 2 properties?

查看:116
本文介绍了BOOL Obj-C 2属性的命名约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个readonly BOOL属性。这里是主要命名模式?

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;

在@property世界中,通常表示为

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

@property(getter=isEditable) BOOL editable;

但是,有相反的例子。如CalStore / CalCalendar.h

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

@property(readonly) BOOL isEditable;

(CalCalendar在这里错误,或者也是只读BOOL属性的可接受命名模式?)

(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;

哪种模式是最自然的还是类Cocoa的?

Which pattern is most natural or Cocoa-like?

推荐答案

引用自 ADC


如果属性表示为
形容词,格式为:

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

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

例如:

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

如果属性表示为动词,格式为:

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

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

例如:

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

动词应为简单现在时。

| K <

这篇关于BOOL Obj-C 2属性的命名约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆