Access Control keywords in swift: open, public, internal, fileprivate, private, and swiftfileprivate

Source: Internet
Author: User

Access Control keywords in swift: open, public, internal, fileprivate, private, and swiftfileprivate

Although Access Control is a basic knowledge, it contains a wide range of rules. This article describes some of them for your convenience.
The access control model in swift is based on the concepts of module and Source File. The module refers to the Framework or App bundle. In swift, you can use the import keyword to introduce your own project. The source File refers to the swift File in Swift, which is the File for compiling swift code, it generally belongs to a certain module.
Access Control keyword permissions after swift3 are listed in the descending order: open (public permission), public (public access permission), and internal (internal permission is also the default permission), fileprivate (file private permission), private (private permission) Five.

Open: can be accessed, inherited, and rewritten anywhere. Public: it can be accessed anywhere and cannot be inherited or overwritten in other modules. Internal: can be accessed in the entire module. Fileprivate: its modified attributes can be accessed, inherited, and rewritten to the same file. The same file refers to the same swift file, and one file can have multiple classes. Private: the modified attributes and methods can only be accessed and used in this class.

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.