Swift’s access control model is based on the concept of modules and source files.
Swift的访问控制模型基于模块和源文件的概念。
模块主要是target sdk等
You can assign specific access levels to individual types (classes, structures, and enumerations), as well as to properties, methods, initializers, and subscripts belonging to those types. Protocols can be restricted to a certain context, as can global constants, variables, and functions.
为特定的类型(classes, structures, and enumerations)、properties, methods, initializers 设置限制访问权限
关键字(按使用权限 高--低 排序)
open 模块内外都可以访问 包括继承、重写
public 模块内外都可以访问 但是只能在模块内可以继承、重写
internal 只可以在模块内使用针对的是source files 模块外不可以访问
fileprivate 针对的是source file 只属于该文件内 文件外不可以直接访问
private 只能在其所属的{}内访问
网友评论