Swift 访问控制

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 只能在其所属的{}内访问

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容