나의 발자취

접근제어자 PROPERTIES AND ACCESS CONTROL 본문

앱 개발/iOS

접근제어자 PROPERTIES AND ACCESS CONTROL

달모드 2023. 7. 22. 01:14

Levels of Access

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.

 

 

출처: codecademy

728x90
반응형

'앱 개발 > iOS' 카테고리의 다른 글

iOS 파일시스템 이해하기  (1) 2023.10.07
클래스  (0) 2023.09.03
Swift 함수 한번에 정리  (0) 2023.06.30
if-let 구문, 옵셔널 바인딩  (0) 2023.06.28
튜플 특징  (0) 2023.06.28
Comments