Access control (public/internal/fileprivate/private)
Control visibility of APIs across files and modules using public, internal (default), fileprivate, and private. Learn when to expose vs hide.
Access levels overview
Swift access levels:
- public: visible to other modules
- internal (default): visible in the same module
- fileprivate: only this source file
- private: enclosing scope (type/extension)
internal (default)
Omitting a modifier makes declarations internal, usable anywhere within the same module (package/app target).
struct Greeter { // internal by default
func hello(_ name: String) -> String { "Hello, \\(name)" }
}
let g = Greeter()
print(g.hello("Ada"))All lessons in this course
- Memberwise init & mutating methods
- Inheritance, overriding & final
- Access control (public/internal/fileprivate/private)