8
8
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9
9
*/
10
10
11
- /// Defines a package product.
11
+ /// The object that defines a package product.
12
12
///
13
- /// A package product defines an externally visible build artifact that is
13
+ /// A package product defines an externally visible build artifact that's
14
14
/// available to clients of a package. The product is assembled from the build
15
15
/// artifacts of one or more of the package's targets.
16
16
///
17
17
/// A package product can be one of two types:
18
18
///
19
- /// 1. Library
19
+ /// Library
20
20
///
21
- /// A library product is used to vend library targets containing the public
22
- /// APIs that will be available to clients .
21
+ /// Use a library product to vend library targets. This makes a target's public APIs
22
+ /// available to clients that integrate the Swift package .
23
23
///
24
- /// 2. Executable
24
+ /// Executable
25
25
///
26
- /// An executable product is used to vend an executable target. This should
27
- /// only be used if the executable needs to be made available to clients.
26
+ /// Use an executable product to vend an executable target.
27
+ /// Use this only if you want to make the executable available to clients.
28
28
///
29
29
/// The following example shows a package manifest for a library called "Paper"
30
30
/// that defines multiple products:
@@ -63,14 +63,14 @@ public class Product: Encodable {
63
63
case type = " product_type "
64
64
}
65
65
66
- /// The name of the product.
66
+ /// The name of the package product.
67
67
public let name : String
68
68
69
69
init ( name: String ) {
70
70
self . name = name
71
71
}
72
72
73
- /// Represents an executable product.
73
+ /// The executable product of a Swift package .
74
74
public final class Executable : Product {
75
75
private enum ExecutableCodingKeys : CodingKey {
76
76
case targets
@@ -84,6 +84,12 @@ public class Product: Encodable {
84
84
super. init ( name: name)
85
85
}
86
86
87
+ /// Encodes this executable product into the given encoder.
88
+ ///
89
+ /// This function throws an error if any values are invalid for the given encoder’s format.
90
+ ///
91
+ /// - Parameters:
92
+ /// - encoder: The encoder to write data to.
87
93
public override func encode( to encoder: Encoder ) throws {
88
94
try super. encode ( to: encoder)
89
95
var productContainer = encoder. container ( keyedBy: ProductCodingKeys . self)
@@ -93,14 +99,14 @@ public class Product: Encodable {
93
99
}
94
100
}
95
101
96
- /// Represents a library product.
102
+ /// The library product of a Swift package .
97
103
public final class Library : Product {
98
104
private enum LibraryCodingKeys : CodingKey {
99
105
case type
100
106
case targets
101
107
}
102
108
103
- /// The type of library product.
109
+ /// The different types of a library product.
104
110
public enum LibraryType : String , Encodable {
105
111
case `static`
106
112
case `dynamic`
@@ -111,7 +117,8 @@ public class Product: Encodable {
111
117
112
118
/// The type of the library.
113
119
///
114
- /// If the type is unspecified, package manager will automatically choose a type.
120
+ /// If the type is unspecified, the Swift Package Manager automatically
121
+ /// chooses a type based on the client’s preference.
115
122
public let type : LibraryType ?
116
123
117
124
init ( name: String , type: LibraryType ? = nil , targets: [ String ] ) {
@@ -120,6 +127,12 @@ public class Product: Encodable {
120
127
super. init ( name: name)
121
128
}
122
129
130
+ /// Encodes this library product into the given encoder.
131
+ ///
132
+ /// This function throws an error if any values are invalid for the given encoder’s format.
133
+ ///
134
+ /// - Parameters:
135
+ /// - encoder: The encoder to write data to.
123
136
public override func encode( to encoder: Encoder ) throws {
124
137
try super. encode ( to: encoder)
125
138
var productContainer = encoder. container ( keyedBy: ProductCodingKeys . self)
@@ -130,12 +143,13 @@ public class Product: Encodable {
130
143
}
131
144
}
132
145
133
- /// Create a library product that can be used by clients that depend on this package.
146
+ /// Create a library product to allow clients that declare a dependency on this package
147
+ /// to use the package’s functionality.
134
148
///
135
- /// A library' s product can either be statically or dynamically linked. It
136
- /// is recommended to not declare the type of library explicitly to let the
137
- /// Swift Package Manager choose between static or dynamic linking depending
138
- /// on the consumer of the package.
149
+ /// A library’ s product can either be statically or dynamically linked.
150
+ /// If possible, don’t declare the type of library explicitly to let
151
+ /// the Swift Package Manager choose between static or dynamic linking based
152
+ /// on the preference of the package's consumer .
139
153
///
140
154
/// - Parameters:
141
155
/// - name: The name of the library product.
@@ -151,18 +165,24 @@ public class Product: Encodable {
151
165
return Library ( name: name, type: type, targets: targets)
152
166
}
153
167
154
- /// Create an executable product.
168
+ /// Create an executable package product that clients can run .
155
169
///
156
170
/// - Parameters:
157
171
/// - name: The name of the executable product.
158
- /// - targets: The targets that are bundled into an executable product.
172
+ /// - targets: The targets to bundle into an executable product.
159
173
public static func executable(
160
174
name: String ,
161
175
targets: [ String ]
162
176
) -> Product {
163
177
return Executable ( name: name, targets: targets)
164
178
}
165
179
180
+ /// Encodes this product into the given encoder.
181
+ ///
182
+ /// This function throws an error if any values are invalid for the given encoder’s format.
183
+ ///
184
+ /// - Parameters:
185
+ /// - encoder: The encoder to write data to.
166
186
public func encode( to encoder: Encoder ) throws {
167
187
var container = encoder. container ( keyedBy: ProductCodingKeys . self)
168
188
try container. encode ( name, forKey: . name)
0 commit comments