问题
Usually your class have many methods. Its annoying to set the access modifier for all of them as private and keep one or two with no access modifier.
Is there a way to let all methods private by default and give the access modifier to the public ones? maybe by assigning an access modifier for the class.
回答1:
Move all your private methods to an extension in the same file and mark it as fileprivate.
class Foo {
// public stuff, stored properties etc.
}
fileprivate extension Foo {
// private methods, computed properties etc.
func bar() {
// this method is fileprivate
}
}
来源:https://stackoverflow.com/questions/40692367/class-methods-access-level-internal-by-default