본문 바로가기

iOS/swift

[swift] Access Control

반응형

Access control restricts access to parts of your code from code in other source files and modules. This feature enables you to hide the implementation details of your code, and to specify a preferred interface through which that code can be accessed and used.

접근 제어는 다른 자료 파일들과 독립적인 구성요소(모듈) 안의 소스에서 네 코드의 일부분에 대한 접근을 제한합니다. 이 특징은 네가 네 코드의 수행 세부사항을 숨길 수 있게 해 줍니다. 그리고 접근 제어를 통한 우선되는(선호하는) 접점을 명시할 수 있게 해 줍니다.

You can assign specific access levels to individual types (classes, structures, and enumerations), as well as to properties, methods, initializers, and subscripts belonging to those types. Protocols can be restricted to a certain context, as can global constants, variables, and functions.

In addition to offering various levels of access control, Swift reduces the need to specify explicit access control levels by providing default access levels for typical scenarios. Indeed, if you are writing a single-target app, you may not need to specify explicit access control levels at all.

NOTE

The various aspects of your code that can have access control applied to them (properties, types, functions, and so on) are referred to as “entities” in the sections below, for brevity.

Modules and Source Files

Swift’s access control model is based on the concept of modules and source files.

A module is a single unit of code distribution—a framework or application that’s built and shipped as a single unit and that can be imported by another module with Swift’s import keyword.

Each build target (such as an app bundle or framework) in Xcode is treated as a separate module in Swift. If you group together aspects of your app’s code as a stand-alone framework—perhaps to encapsulate and reuse that code across multiple applications—then everything you define within that framework will be part of a separate module when it’s imported and used within an app, or when it’s used within another framework.

A source file is a single Swift source code file within a module (in effect, a single file within an app or framework). Although it’s common to define individual types in separate source files, a single source file can contain definitions for multiple types, functions, and so on.

반응형

'iOS > swift' 카테고리의 다른 글

[Swift] AVFoundation 이용하기  (0) 2021.10.24
[swift] collectionview 사용하기  (0) 2021.08.21
[swift] view memory 화면 설명  (0) 2021.08.09
[swift] Dictionary initializer with grouping  (0) 2021.08.06
[swift] 컨트롤러간 화면 전환  (0) 2021.08.04

]