Check Mobile App
Read now
Start a Project

Access Control in swift

Save

Access Control main purpose is to prevent the access of code in other modules or files. By access control code accessibility can be handle. By using Access control we can assign the specific access level to the class, structure, enumerations, properties, subscripts, methods, initializers.

Types of Access control:-

  1. Open
  2. Public
  3. internal
  4. fileprivate
  5. private

 

1) Open:- It has the highest access level means it is the least restrictive.  It provides access levels from other modules and files.

2) Public:-It is almost similar to open but unlike open which is subclassed and override from other modules. By using the public we can not subclassed and override from defining modules.

Let takes an example to differentiate between Open and Public.

3) internal:- It is default access control. The method or class which declares internal can be accessed from anywhere within the same module.

For Example

4) filePrivate:- The fileprivate gives accessibility within one single swift file.

For Example

5) private:- It has the lowest access level means it is the highest restrictive. It restricts the entity to the enclosing declaration. According to swift doc “Use private access to hide the implementation details of a specific piece of functionality when those details are used only within a single declaration.”

For example

Thanks for reading the blog.

You can also check other blogs from here. if you have any issue or suggestion you can leave your query/suggestion in the comment section.

Reference

. . .

Leave a Comment

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


Be the first to comment.

css.php

The support is fast and do everything in their power to make it perfect. If you need customization it's also done right away. I had massive research to select Mobikul and now I'm sure it was the right one.

Igor Souza

Igor Souza

Talk to Sales

Global

Live Chat
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home