Access control on swift extension

Asked on 03/05/2025

1 search

In Swift, access control is an important feature that allows you to define the visibility and accessibility of your code components. When it comes to Swift extensions, you can use access control to manage how and where your extensions can be accessed.

In the session titled "A Swift Tour: Explore Swift’s features and design" from WWDC 2024, access control levels in Swift are discussed. Swift provides several access control levels:

  • Private: Accessible only within the same file.
  • Internal: Accessible within the same module. This is the default access level if none is specified.
  • Package: Accessible from other modules in the same package.
  • Public: Accessible from any other module.

These access control levels can be applied to extensions as well. For example, you can define an extension with a public access level to make its methods and properties accessible from outside the module.

For more detailed information, you can refer to the session A Swift Tour: Explore Swift’s features and design (10:59) where access control is discussed in the context of Swift's features and design.