Learn

Public We’ll start with public, the most open level, which grants access to a property or method from inside or outside the module. Relating it to the company analogy, since modules are companies, public information can be shared between companies. This level is typically used when creating frameworks so that modules that import the framework can access its properties and methods.

Internal The next level, in order of least to most restrictive, is internal. This is the default level for all properties and methods, so it is active if no access level is specified. Internal grants access to properties and methods within a module. So in our company analogy, internal would be the information that can be shared with anyone within the company. Having everything internal by default is convenient because you can easily access properties and methods across source files, but there may be cases where this could lead to problems, so we might want to impose a more restricted level of access control.

Fileprivate Fileprivate is the next level, and it grants access to properties and methods within a source file. Remember source files are the divisions of our company, so this is the information that can be shared within a given division between any office.

Private Finally, the most restrictive level of access is private, which restricts access to a property or method within a structure. Since structures are the offices in our analogy, this is information only to be shared within an office of a division of a company.

Open Additionally, there is open which is similar to public in that it allows access from other modules. However, it only applies to classes and class members. We will learn about classes in another lesson, but open is an access level you should be aware of.

Don’t worry if this is all still a bit abstract, we will build on the company analogy throughout the lesson to illustrate the value of access control when developing Swift applications.

Instructions

1.

Comment out the invalid line so the code runs without errors.

Take this course for free

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?