If let name = Optionname {} In Swift explanation

Source: Internet
Author: User

This is not the case in the IF statement of the SWIFT syntax:

1 " Swift " 2 if let name = optionname {3     print ("OK") 4 }

However, the following can occur:

" Swift " if let name = optionname {    print ("OK")}

Let name = Optionname

When Optionname is an optional type, the above line of code syntax is called, optional binding

Explain:

The optional binding (optional binding) is used to determine whether an optional type contains a value, and if it is included, assigns the value to a temporary constant or variable. Optional bindings can be used in the IF and while statements, which can be used not only to determine whether there are values in an optional type, but also to assign values from an optional type to a constant or variable. ”

So. The first is to determine whether there is a value in Optionname, if so, assign the value to name, and then go to {}, otherwise skip large {}

If let name = Optionname {} In Swift explanation

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.