Swift provides different accessibility levels to codes. They include privatefileprivateinternalpublic and open. This feature can restrict other developer from accessing, extending and overriding the creator’s implementation. It is useful when a framework/ library is created and shared among different developers.

Image for post

Before start, it is necessary to have a clear understanding on what a module is. Module is an individual unit of code distribution, e.g. your app and 3rd party that is installed through CocoaPods.

open and public are used to declare code accessibility level across different modules. internalfileprivate and private are used at the Swift file level.

Access Control — Private

Image for post

private means the declared code (classstructenumproperty and method, etc) can only be accessed within the current enclosing type.

Image for post

extension scope can only access those private properties only when it is declared at the same file of the extended classstruct and enum.

#ios-app-development #ios #access-control #ios-development #swift-programming

Swift Basic — Access Control
1.35 GEEK