can class is internal access and methods within class public access

Generated on 10/30/2024

1 search

In Swift, access control is an important feature that allows you to define the visibility and accessibility of classes, methods, and other entities. According to the session "A Swift Tour: Explore Swift’s features and design" from WWDC 2024, Swift provides several access control levels:

  • Public: Accessible from any other module.
  • Internal: Accessible only within the same module.
  • Private: Accessible only within the same file.

If you have a class with internal access, it means that the class is accessible only within the same module. Methods within this class can have public access, which means they can be accessed from any other module, but only if the class itself is accessible. Therefore, if the class is internal, its public methods are effectively internal as well, because the class cannot be accessed from outside the module.

For more details on access control in Swift, you can refer to the session A Swift Tour: Explore Swift’s features and design (10:59).