Private Over Fileprivate
ID |
swift.private_over_fileprivate |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Swift |
Tags |
code-smell, encapsulation |
Description
Reports the use of the fileprivate access-level modifier. In most
cases private is the correct choice — it limits visibility to the
enclosing declaration (and its extensions in the same file), which is
strictly tighter.
fileprivate var counter = 0 // FLAW
private var counter = 0 // OK
Rationale
fileprivate was introduced for the case where one type in a file
needs to reach into another type in the same file. That situation is
real but rare. Most properties and methods marked fileprivate could
be private instead.
Remediation
Replace fileprivate with private:
private var counter = 0
private func helper() { }
If the symbol really needs cross-type access inside the file, leave
the modifier as fileprivate and silence the warning case-by-case.