通常你的班级有很多方法.将所有这些的访问修饰符设置为私有并且保持一个或两个没有访问修饰符很烦人.
有没有办法让所有方法默认为私有,并将访问修饰符赋予公共方法?也许通过为类分配访问修饰符.
将所有私有方法移动到同一文件中的扩展名并将其标记为fileprivate.
class Foo {
// public stuff, stored properties etc.
}
fileprivate extension Foo {
// private methods, computed properties etc.
func bar() {
// this method is fileprivate
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
132 次 |
| 最近记录: |