默认情况下,类方法访问级别内部

has*_*san 3 ios swift swift3

通常你的班级有很多方法.将所有这些的访问修饰符设置为私有并且保持一个或两个没有访问修饰符很烦人.

有没有办法让所有方法默认为私有,并将访问修饰符赋予公共方法?也许通过为类分配访问修饰符.

Nik*_*uhe 7

将所有私有方法移动到同一文件中的扩展名并将其标记为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)