In Swift, Optional,? And! The relationship between

Source: Internet
Author: User

In Swift, Optional,? And! The relationship between

Optional <ClassName> equivalence with ClassName?

Yes, ClassName! forcing a value causes a crash ( if the object is nil, the value crashes )

imageview!. Image is a imageView forced unpacking, ImageView. image! is the forced unpacking of the image, and if it is found to be nil after unpacking, the crash

Apart from! And? , there is a kind of thing called nilliteralconvertible

'? ' must is followed by a call, member lookup, or subscript

Summary

1. Use a question mark? The object allows nil to appear, using an exclamation point! The object appears nil will crash

2. Use a question mark? Scenarios require content on the right side of the object, except when declared

3. Can I put a question mark? With an exclamation point! Understood as unpacking operations,? Support Package is empty, and! Crashes when the package is empty

In Swift, Optional,? And! The relationship between

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.