Search code examples
iosswiftstatic-analysis

How can I find all functions that have no access level specified?


We have a big quantity of functions in legacy-code that have no access level specified, so they all fall back into the default access level, "Internal". I would like to make them all "Private" and see if there are any build errors, so that I can quickly tell if some of them should be converted to Private. I can't find a quick way of doing that. Does anyone know of a tool or a trick for that? Maybe a shell script or a linter with this feature?


Solution

  • Use the following Regular Expression. It matchs all lines that starts with func.

    ^\s*func
    
    • ^ matches start of line

    • \s* matches any number of space. You may have different levels of indentation.

    enter image description here

    update

    You can use or (|) operator to match @objc and mutating.

    ^\s*func|@objc|mutating
    

    Info:

    You may not need to change the access modifiers in SceneDelegate and AppDelegate. If so, click on In Project and then choose the following search scope.

    enter image description here