Swift some syntax

Source: Internet
Author: User

1. Function permissions

    • Public: Maximum permissions that can be accessed in the current framework and other frameworks
      Internal: Default permissions that can be accessed freely in the current framework
      Private: Personal permissions, accessible only in the current file
The development of the proposed strict control permissions, do not want to let others access things must be private2 、?? operator

    • ?? Used to determine if the preceding parameter is nil, and if it is nil, return?? After the data, if not nil then?? The following statement does not execute
      • var string:string? = Nil
        Let title = string?? "String = nil"
        Print (title)//String = Nil

        String = "String! = nil"
        Let Title1 = string?? "String = nil"
        Print (Title1)//String! = Nil

3. Type conversion as! As?

    • as! The forced format of a type conversion, if it can be converted, returns an object that has been converted, and a run-time error is thrown when it cannot be converted. Therefore, you should not use as! unless you are absolutely sure that you can convert To perform a forced type conversion.
    • As? Returns an optional type of the converted type, if the conversion succeeds in returning an optional value, otherwise the optional value is nil, and because it is an optional type, it is recommended to use this method for type conversion, even if the conversion fails.

Swift some syntax

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.