ios developer tiny share-20160812
来源:互联网 发布:to the moon 音乐 知乎 编辑:程序博客网 时间:2024/06/06 06:51
今天讲Objective-C的类方法,类方法和类属性在前面写一个“+”号,和instance method方法的“-”对应。具体如下:
Objective-C Classes Are also Objects
In Objective-C, a class is itself an object with an opaque type called Class. Classes can’t have properties defined using the declaration syntax shown earlier for instances, but they can receive messages.
The typical use for a class method is as a factory method, which is an alternative to the object allocation and initialization procedure described in Objects Are Created Dynamically. The NSString class, for example, has a variety of factory methods available to create either an empty string object, or a string object initialized with specific characters, including:
+ (id)string;+ (id)stringWithString:(NSString *)aString;+ (id)stringWithFormat:(NSString *)format, …;+ (id)stringWithContentsOfFile:(NSString *)path encoding:(NSStringEncoding)enc error:(NSError **)error;+ (id)stringWithCString:(const char *)cString encoding:(NSStringEncoding)enc;
As shown in these examples, class methods are denoted by the use of a + sign, which differentiates them from instance methods using a - sign.
Class method prototypes may be included in a class interface, just like instance method prototypes. Class methods are implemented in the same way as instance methods, inside the @implementation block for the class.
0 0
- ios developer tiny share-20160812
- ios developer tiny share-20160628
- ios developer tiny share-20160629
- ios developer tiny share-20160630
- ios developer tiny share-20160701
- ios developer tiny share-20160704
- ios developer tiny share-20160705
- ios developer tiny share-20160706
- ios developer tiny share-20160707
- ios developer tiny share-20160708
- ios developer tiny share-20160711
- ios developer tiny share-20160712
- ios developer tiny share-20160713
- ios developer tiny share-20160714
- ios developer tiny share-20160715
- ios developer tiny share-20160718
- ios developer tiny share-20160719
- ios developer tiny share-20160720
- sdk adt ide avd adb
- 架构师之路
- JavaEE——properties配置文件的编写和解析获取
- CodeForce 510 B
- 【HD 1242】(重写/模板)Rescue
- ios developer tiny share-20160812
- C++学习014函数值传递和地址传递
- 生成环境中grunt的压缩使用
- 可见性修饰符
- 函数式编程
- SpringMVC拦截器
- C# 发邮件 Code
- ERROR 1292 (22007): Truncated incorrect DOUBLE value: '96133dby11'
- jquery traditional true 的问题