Press ESC to close

Open – Public – Internal – Private (Access Levels)

Hello friends, in this article, we can use Swift to create variables, functions, classes, extensions, etc. We will talk about the Access Levels part that we use when creating structures. In every programming language, we need to pay attention to the access level when creating variables. As you know, this is very important when we work as a team or for people who will continue the project after us. For this, Swift offers us 5 different access levels. These;

  • Open
  • Public
  • Internal
  • Private
  • File-private

Open

Variables created with the open access type can be used in the same module or in other modules. You can inherit or override classes created with Open in other modules.

Public

It is similar to Open. The only difference is that you cannot inherit or override in different modules.

Internal

If you have not created a variable with Swift and set an access level, Internal is defined by default. You can use variables defined as internal in the same module, but you cannot access them from different modules.

Private 

You can use variables or functions defined with Private only in the class they are in or in inherited classes.

File-private

Variables defined as file private can only be used in the defined file. Even if it is inherited or an extension is attempted, it cannot be accessed when it is in a different file.

More information can be found here. You can find my other articles about Swift here.

If you have questions, you can reach us by sending an e-mail or comment. Good work.

Leave a Reply

Your email address will not be published. Required fields are marked *