@@ -23,9 +23,10 @@ you may not need to specify explicit access control levels at all.
23
23
> (properties, types, functions, and so on)
24
24
> are referred to as “entities” in the sections below, for brevity.
25
25
26
- ## Modules and Source Files
26
+ ## Modules, Source Files, and Packages
27
27
28
- Swift's access control model is based on the concept of modules and source files.
28
+ Swift's access control model is based on the concept of
29
+ modules, source files, and packages.
29
30
30
31
A * module* is a single unit of code distribution ---
31
32
a framework or application that's built and shipped as a single unit
@@ -44,17 +45,36 @@ A *source file* is a single Swift source code file within a module
44
45
Although it's common to define individual types in separate source files,
45
46
a single source file can contain definitions for multiple types, functions, and so on.
46
47
48
+ A * package* is a group of modules that you develop as a unit.
49
+ You define the modules that form a package
50
+ as part of configuring the build system you're using,
51
+ not as part of your Swift source code.
52
+ For example, if you use Swift Package Manager to build your code,
53
+ you define a package in your ` Package.swift ` file
54
+ using APIs from the [ PackageDescription] [ ] module,
55
+ and if you use Xcode, you specify the package name
56
+ in the Package Access Identifier build setting.
57
+
58
+ [ PackageDescription] ( https://developer.apple.com/documentation/packagedescription )
59
+
47
60
## Access Levels
48
61
49
- Swift provides five different * access levels* for entities within your code.
62
+ Swift provides six different * access levels* for entities within your code.
50
63
These access levels are relative to the source file in which an entity is defined,
51
- and also relative to the module that source file belongs to.
64
+ the module that source file belongs to,
65
+ and the package that the module belongs to.
52
66
53
67
- * Open access* and * public access*
54
68
enable entities to be used within any source file from their defining module,
55
69
and also in a source file from another module that imports the defining module.
56
70
You typically use open or public access when specifying the public interface to a framework.
57
71
The difference between open and public access is described below.
72
+ - * Package access*
73
+ enables entities to be used within
74
+ any source files from their defining package
75
+ but not in any source file outside of that package.
76
+ You typically use package access
77
+ within an app or framework that's structured into multiple modules.
58
78
- * Internal access*
59
79
enables entities to be used within any source file from their defining module,
60
80
but not in any source file outside of that module.
@@ -790,14 +810,15 @@ the constant, variable, property, or subscript they belong to.
790
810
You can give a setter a * lower* access level than its corresponding getter,
791
811
to restrict the read-write scope of that variable, property, or subscript.
792
812
You assign a lower access level by writing
793
- ` fileprivate(set) ` , ` private(set) ` , or ` internal (set)`
813
+ ` fileprivate(set) ` , ` private(set) ` , ` internal(set) ` , or ` package (set)`
794
814
before the ` var ` or ` subscript ` introducer.
795
815
796
816
> Note: This rule applies to stored properties as well as computed properties.
797
817
> Even though you don't write an explicit getter and setter for a stored property,
798
818
> Swift still synthesizes an implicit getter and setter for you
799
819
> to provide access to the stored property's backing storage.
800
- > Use ` fileprivate(set) ` , ` private(set) ` , and ` internal(set) ` to change the access level
820
+ > Use ` fileprivate(set) ` , ` private(set) ` , ` internal(set) ` , and ` package(set) `
821
+ > to change the access level
801
822
> of this synthesized setter in exactly the same way as for an explicit setter
802
823
> in a computed property.
803
824
0 commit comments