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.