Swift in as as! The difference between as?

Source: Internet
Author: User

As: Type consistent or sub-class

This value is only matched if the type of a value is the same as 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.

class Animal {} class  = as Animal

as! Parent class strong Rotor class

class Animal {} class  =as! Dog

No more! Compile will error

As? Conversion failure returns nil

class Animal {} class Dog:animal {} class  =as!  as? Dog

Animal as! The Dog compiler will error the as?

Swift in as as! The difference between as?

Related Article

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.