IT English Collection(22)of Accessor method
2013-10-18 18:12
453 查看
1 前言
本章主要介绍了Objective-C中的存取方法的相关内容。2 详述
2.1 原文
Anaccessor method is an instance method that gets or sets the value of a property of an object. In Cocoa’s
terminology, a method that
retrieves the value of an object’s property is referred to as a getter method, or “getter;” a method that changes the value of an object’s property is referred to as a setter method, or “setter.” These methods are often found in pairs, providing API
for getting and setting the property values of an object.
You should use accessor methods rather than directly accessing state data because they provide an abstraction layer. Here are just two of the benefits that accessor methods provide:
·You don’t need to rewrite your code if the manner in which a property is
represented or stored changes.
·Accessor methods often implement important behavior that occurs whenever a value is retrieved or set. For example, setter methods
frequently implement memory management code and notify other objects when a value is changed.
Naming Conventions
Because of the importance of this pattern, Cocoa defines some conventions for naming accessor methods. Given a property of type
type and called name, you should typically implement accessor methods with the following form:
- (type)name; - (void)setName:(type)newName;
The one exception is a property that is a Boolean value. Here the getter method name may be isName. For example:
- (BOOL)isHidden; - (void)setHidden:(BOOL)newHidden;
This naming convention is important because much other
functionality in Cocoa
relies upon it, in particular key-value coding. Cocoa does not use getName because methods that start with “get” in Cocoa
indicate that the method will return values by reference.
2.2 生词
accessor n. [计]存取器;访问器
terminology
[,tə:mi'nɔlədʒi]n. 术语,术语学;用辞
retrieve
[ri'tri:v]vt. [计] 检索;恢复
abstraction
[əb'strækʃ(ə)n]n. 抽象;提取
benefit
['benɪfɪt]n. 利益,好处
manner ['mænə]n.
方式;习惯
represented
[reprɪ'zentɪd]v. 代表;表现;描写
behavior
[bi'heivjə]n. 行为,举止
frequently
['friːkw(ə)ntlɪ]adv. 频繁地,经常地;
Convention
[kən'venʃ(ə)n] n. [法]
惯例;会议
functionality
[,fʌŋkʃə'næliti]n. 功能;
relies 信任
particular
[pə'tɪkjʊlə]adj. 特别的;详细的
indicate
['ɪndɪkeɪt]vt. 表明;指出
3 结语
以上是所有内容,希望对大家有所帮助。相关文章推荐
- IT English Collection(14) of Storyboard
- IT English Collection(28)of Property list
- IT English Collection(9) of Objective-C
- IT English Collection(18)of Target-Action
- IT English Collection(26) of Undo manager
- IT English Collection(21)of Key-value coding
- IT English Collection(27)of Collection
- My collection of English phrases(4)
- Overview of English study method
- Invocation of init method failed;... Result Maps collection already contains value for
- IOS深入学习(22)之Accessor method
- IT English Collection(2)of Formatter(IOS)
- My collection of English phrases(2)
- 绑定到异步的ObservableCollection [This type of CollectionView does not support changes to its SourceColl]
- iOS升级swift3 遇到Overriding non-open instance method outside of its defining module的解决方案
- My collection of English phrases(1)
- My collection of English phrases(3)
- Method of learning English?
- Crossing Boundaries: The Deployment of Global IT Solutions
- 关于error:Cannot assign to 'self' outside of a method in the init family