swift类型操作规范

type(of:)

Applied to an object: the polymorphic (internal) type of the object, regardless of how a reference is typed. Static/class members are accessible by passing an object to type(of:).

.Type

Sent to a type in a type declaration: the polymorphic type. For example, in a function parameter declaration, Dog means a Dog instance is expected (or an instance of one its subclasses), but Dog.Type means that the Dog type itself is expected (or the type of one of its subclasses).

.self

Sent to a type: the type. For example, to pass the Dog type where Dog.Type is expected, you can pass Dog.self.

self

In instance code, this instance, polymorphically. In static/class code, this type, polymorphically; self.init(...) instantiates the type.

Self

In a method declaration, when specifying the return type, this class or this instance’s class, polymorphically.

http://www.apeth.com/swiftBook/ch04.html#_type_reference

猜你喜欢

转载自www.cnblogs.com/feng9exe/p/9106390.html