Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class methods access level internal by default

Tags:

ios

swift

swift3

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.

like image 760
hasan Avatar asked May 25 '26 18:05

hasan


1 Answers

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
    } 
}
like image 65
Nikolai Ruhe Avatar answered May 28 '26 07:05

Nikolai Ruhe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!