0Pricing
Swift Academy · Lesson

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

  1. Memberwise init & mutating methods
  2. Inheritance, overriding & final
  3. Access control (public/internal/fileprivate/private)
← Back to Swift Academy