Swift-----Access Control (private, fileprivate, internal, public, open)

Source: Internet
Author: User
Tags modifiers

In Swift, there are five types of access modifiers: private, fileprivate, internal, public, open. Where Fileprivate and open are newly added to Swift 3. Because the previous access control is file-based, it is not class-based. This can be problematic, so Swift 3 adds two modifiers, which subdivide the original private and public.

The ranking from high to Low is as follows:

  Open > Public > Interal > Fileprivate > Private

(1) Private: a modified property or method can only be accessed in the current class.

(2) Fileprivate: The Modified property or method can only be accessed in the current file. If a file contains more than one class, it can be accessed.

(3) Internal: Default access level, can write not write.

The decorated properties and methods can be accessed throughout the source code of the module.

If it is a frame or library code, it can be accessed throughout the framework and not accessible outside the framework.

If it's an app code, it's accessible throughout the app.

(4) Public: can be accessed by any code. But other modules can not be override and inherit, but within the module can be override and inherit.

(5) Open: can be accessed by any module's code, including override and inheritance.

Swift-----Access Control (private, fileprivate, internal, public, open)

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.