Objective-C Classes Are also Objects
2017-07-24 19:19
218 查看
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/DefiningClasses/DefiningClasses.html#//apple_ref/doc/uid/TP40011210-CH3-SW18
In Objective-C, a class is itself an object with an opaque type called
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
As shown in these examples, class methods are denoted by the use of a
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
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
NSStringclass, 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; |
+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
@implementationblock for the class.
相关文章推荐
- Classes, Objects, and Methods(Chapter 3 of Programming in Objective-C 2.0)
- 第十节--抽象方法和抽象类 -- Classes and Objects in PHP5 [10]
- [Objective-C]关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)
- Java学习笔记(9)Objects and Classes
- 第十二节--类的自动加载 -- Classes and Objects in PHP5 [12](转)
- [Objective-C]关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)
- Chapter 2 Classes and Objects
- ARC forbids Objective-C objects in struct
- 【Core java v1】ch4 OBJECTS AND CLASSES
- Objects and Classes in Ruby
- Objective-C Associated Objects 的实现原理
- Objective-C Associated Objects 的实现原理
- !!!Obj-C 2.0 -- Chapter 1 Objects, Classes, and Messaging
- Classes and objects(类和对象)
- case classes & case companion objects & case objects
- Classes and Objects :类和对象(2)
- 第十二节--类的自动加载 -- Classes and Objects in PHP5 [12]
- [Objective-C]关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)
- Classes and Objects in PHP5-面向对象编程 [1]
- 第十三节--对象串行化 -- Classes and Objects in PHP5 [13](转)