Swift type system self self type

Source: Internet
Author: User

Namedclass: Static type, directly associated with type implementation, can be used for initialization, type checking, and so on.

Namedclass.self: @thick, desensitization (off-off) type, dynamic type, can be used as an instance of meta-type, can be passed as a type parameter, can be used for inheritance system;

When you initialize with a desensitization type, you need to bind to a specific type.

Namedclass.type: meta type; for desensitization type declaration; desensitization type type check.

Dynamic type: Compile-time indeterminate type designation.

Self: The specific type when dynamic.

Self:in that context, Self refers to the eventual type that conforms to the protocol.

Represents the actual type of a specific, dynamic type.

Https://docs.swift.org/swift-book/ReferenceManual/Declarations.html

"Self" was a placeholder used in the different cases:

1. In a protocol, it refers to the type of the conforms to the Protocol of any particular use. In equatable, for example, it's used to require, the and the values being compared are of the same type. It's something like a generic type parameter so you don ' t has to put between the <...> because it ' s deduced from th e context of its use.

2. In a class/static method, it can used as the return type, to indicate that the return type is the type of the class To which the method were sent, rather than the class in which of the method is declared. It ' s similar to ' instancetype ' in obj-c.

anyobject:

An untyped object

The flexible behavior of the ' anyobject ' protocol is similar to

Objective-c ' s ' id ' type. For this reason, imported objective-c types

Frequently use ' anyobject ' as the type for properties, method parameters,

and return values.

///

Casting Anyobject Instances to a known Type

/// ===========================================

///

Objects with a concrete type of ' anyobject ' maintain a specific dynamic

Type and can is cast to that type using one of the type-cast operators

(' as ', ' as? ', or ' as! ').

Swift provides-special types for working with nonspecific types:

    • AnyCan represent an instance of any type at all, including function types.
    • AnyObjectCan represent an instance of any class type.

Swift type system self self type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.