Objective-C(iPhone 开发)
Possible Duplicate:
Explain to me what is a setter and getter
What are setters and getters? couldn't find it on wikipedia and in other places.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不能吗?
http://en.wikipedia.org/wiki/Mutator_method
Couldn't?
http://en.wikipedia.org/wiki/Mutator_method
Getters 和 Setters 是对象上的方法,允许您隐藏某些内容的内部实现,但仍然允许其他对象访问某些内容。它们还允许您在调用它们时执行验证或其他任务。
在 Objective-C 中,它们与属性的概念联系在一起——如果你定义一个属性,你就会得到对象函数的 getter 和 setter。
例如,如果您想知道某件事被请求了多少次怎么办?
现在,在您的 .m 文件中
,只需请求数据,计数也会增加。
这里有更多关于属性的文档这里和@jussi 的链接是对 getter/setter 的更好概述。
Getters and Setters are methods on an object that allow you to hide the internal implementation of something but still allow other objects to access things. They also allow you to do validation or other tasks when they are called.
In objective-c, they are tied to the idea of properties - if you define a property you get getters and setters for the object's function.
For example, what if you wanted to know how many times something has been asked for?
and in your .m file
Now, just by asking for the data, count is incremented as well.
There's more documentation about properties here and @jussi's link is a better overview of getters/setters in general.
它们通常被称为
变异器
和访问器
。搜索
mutator
/accessor
产生以下结果:http://en.wikipedia.org/wiki/Mutator_method
您可以在 Onbjectice 中使用此范例-C 通过 声明的属性:
They are ofter referred to as
mutators
andaccessors
.A search for
mutator
/accessor
yielded following result:http://en.wikipedia.org/wiki/Mutator_method
You can use this paradigm in in Onbjectice-C via declared properties: