Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is extension_access_modifier swiftlint?

I added Swiftlint to a project and I'm having trouble understanding what the warning is for extension_access_modifier. I see it mainly on a class that is declared as public, but there are extensions littered throughout the codebase that adds functionality.

public class Foo {

}

// In SomeOtherClass.swift
extension Foo { // Extension Access Modifier Violation: Prefer to use extension access modifiers
    public func baz()
}

Whenever there is extension Foo in another class, I get that warning on the extension. Would someone explain what it is?

like image 639
Crystal Avatar asked Feb 01 '18 00:02

Crystal


1 Answers

It's clearer to express that your extension is public, rather than all its members:

Prefer:

public extension Foo {
    func bar() { ... }
    func baz() { ... }
    func qux() { ... }
}

over

extension Foo {
    public func bar() { ... }
    public func baz() { ... }
    public func qux() { ... }
}
like image 88
Alexander Avatar answered Oct 05 '22 11:10

Alexander