Swift Object ModelLesson 32Free preview
Access Control
This lesson is part of Swift · All levels
Summary
This lesson discusses Access Control in Swift to limit code accessibility between source files and modules. Swift provides five levels of access control: open, public, internal (default), fileprivate, and private. Proper access control settings ensure the security of the interface and library encapsulation.
Key points
- Level of access control: open, public, internal, fileprivate, and private
- The default access rate if not written is 'internal' (available throughout the target module)
- 'private' restricted access only within the curly braces declaration where it was made and its extension
- 'fileprivate' restricts access only to lines of code within the same .swift file
- 'open' only applies to classes that allow subclassing from outside the module
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.