Broadway Swift Learning Summary (i)

Source: Internet
Author: User

1. As as! As The difference

One, as

From the Chinese API: This value is matched only if the type of a value is consistent with the specified type at runtime (runtime) and the right of the as mode-or subclass of that type. If the match succeeds, the type of the value being matched is converted to as the pattern specified on the left side of the pattern.

The first is that the runtime does not say much, it is important that as the application conditions have 2 kinds of situations:

1, same as "as" to the right type

2, is the subclass of the right type (this is called upward transformation in Java)

The case code is as follows:

Two, as!

In the second case 2, the subclass of the right type will report an error if it encounters the parent class of the right type of the as left type! (as can not be used in the parent class, in the words of Java, the downward transformation is not supported), thus available as! (Strong turn)

The compiler will also prompt you to use the as! , as! Strong turn if the type does not meet will be an error.

Three, as?

As? Equivalent to the optional type if the conversion fails to return nil.

On the code!

Broadway Swift Learning Summary (i)

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.