In Swift? And! The difference

Source: Internet
Author: User

Tags: the difference of div method option declares type to judge a forced operation

Optional type (? ) with the Force parsing operator (!)? is a kind of judgment after unpacking the grammar sugar!  is a forced unpacking syntax sugar when you're not sure you have a value, you can use it. You can use it when you're sure you have a value! ?Several usage scenarios:
1. Declaring a optional value variable
2. Used in the optional value operation, to determine whether to respond to the subsequent operation
3. Optional method for secure call to protocol
4. Using as? Down Transformation (downcast) !的 usage scenarios
1. Forcing the optional value to be split (unwrap)
2. Declaring Implicitly Unwrapped Optionals values, typically used for properties in a class

In Swift? And! The difference

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.

Tags Index: