setEditable 和 isEditable
您好,我是 Objective C 的新手,当我阅读开发人员文档时,我经常看到这一点。
有名为 setEditable 或 setWhateverName 和 isEditable 或 isWhateverName 的方法
set"blabla" 和 is"blabla" 之间有什么区别
,示例是 NSButton 类
-setAlternateTitle
和 -alternateTitle
或
NSImageView 类
-isEditable
和 -setEditable:
我认为这两个示例中的后者都需要参数,而前者则不需要。这是正确的吗?
Hi I'm new to objective c and I see this quite often when I read the developer documentation.
There are methods named setEditable or setWhateverName and isEditable or isWhateverName
What is the difference between the set"blabla" and is"blabla"
and example would be for the NSButton Class
-setAlternateTitle
and -alternateTitle
or
NSImageView class
-isEditable
and -setEditable:
I think that the latter in both examples takes a paramater and the former ones do not. Is this correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这些称为变异方法。它们是您用于访问各种Objective-C 属性,基本上是类成员变量(所谓的ivars 或实例变量),除非您无法直接访问它们。您只能通过 setter 和 getter 方法访问 ivars。
getter 方法获取属性的当前值。对于非布尔属性,它通常被赋予与相关属性相同的名称(例如
-alternateTitle
),或者带有is
前缀的名称(例如-isEditable
) 用于布尔属性。setter 方法为属性设置一个新值。它通常被赋予以
set
为前缀的属性名称,例如-setEditable:
。例如:
These are called mutator methods. They are methods you use for accessing various Objective-C properties, which are basically class member variables (so-called ivars or instance variables), except you can't access them directly. You can only access the ivars through the setter and getter methods.
The getter method gets the current value of the property. It's usually given a name identical to the property in question (such as
-alternateTitle
) for non-boolean properties, or the name with anis
prefix (such as-isEditable
) for boolean properties.The setter method sets a new value for the property. It's usually given a name of the property name prefixed with
set
, e.g.-setEditable:
.For example:
-setAlternateTitle
和-alternateTitle
是基于标准命名的默认 setter 和 getter(例如NSObject
或int
)惯例。setEditable
和isEditable
是布尔 (BOOL
) 属性的传统 setter 和 getter。在布尔情况下,它提高了可读性。请注意,这里的变化仅存在于 getter 中。-setAlternateTitle
and-alternateTitle
are the default setter and getter (e.g.NSObject
orint
), based on standard naming conventions.setEditable
andisEditable
is the conventional setter and getter for boolean (BOOL
) properties. In the boolean case, it improves readability. Note that the variation here is only in the getter.定居者和吸气者有一个模式。
对于非 BOOL ivars,
“M”。
这些是属性创建的默认值,例如:
对于 BOOL ivars 有两种模式:
getter 只是 ivar 名称:“myBoolIvar”——注意没有“get”前缀。 *
或
这些是由属性创建的默认值,例如:
或 分别
There is a pattern to settlers and getters.
For non BOOL ivars
"M".
These are the defaults created by the property, ex:
For BOOL ivars there are two patterns:
the getter is simply the ivar name: "myBoolIvar" -- notice there is no "get" prefix. *
or
These are the defaults created by the property, ex:
or respectively