hasan
hasan

Reputation: 24195

Class methods access level internal by default

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.

Upvotes: 3

Views: 216

Answers (1)

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81878

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
    } 
}

Upvotes: 7

Related Questions