Skip to content

Commit 0293c5c

Browse files
committed
chore(core): Enhanced swift documentation
1 parent bc2347b commit 0293c5c

File tree

8 files changed

+103
-3
lines changed

8 files changed

+103
-3
lines changed

Amplify/Amplify.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,51 @@ import Foundation
1818
///
1919
/// There are two exceptions to this. The `Logging` and `Hub` categories are configured with a default plugin that is
2020
/// available at initialization.
21+
///
22+
/// - Tag: Amplify
2123
public class Amplify {
2224

2325
/// If `true`, `configure()` has already been invoked, and subsequent calls to `configure` will throw a
2426
/// ConfigurationError.amplifyAlreadyConfigured error.
27+
///
28+
/// - Tag: Amplify.isConfigured
2529
static var isConfigured = false
2630

2731
// Storage for the categories themselves, which will be instantiated during configuration, and cleared during reset.
2832
// It is not supported to mutate these category properties. They are `var` to support the `reset()` method for
2933
// ease of testing.
34+
35+
/// - Tag: Amplify.Analytics
3036
public static internal(set) var Analytics = AnalyticsCategory()
37+
38+
/// - Tag: Amplify.API
3139
public static internal(set) var API: APICategory = APICategory()
40+
41+
/// - Tag: Amplify.Auth
3242
public static internal(set) var Auth = AuthCategory()
43+
44+
/// - Tag: Amplify.DataStore
3345
public static internal(set) var DataStore = DataStoreCategory()
46+
47+
/// - Tag: Amplify.Geo
3448
public static internal(set) var Geo = GeoCategory()
49+
50+
/// - Tag: Amplify.Hub
3551
public static internal(set) var Hub = HubCategory()
52+
53+
/// - Tag: Amplify.Notifications
3654
public static internal(set) var Notifications = NotificationsCategory()
55+
56+
/// - Tag: Amplify.Predictions
3757
public static internal(set) var Predictions = PredictionsCategory()
58+
59+
/// - Tag: Amplify.Storage
3860
public static internal(set) var Storage = StorageCategory()
3961

40-
// Special case category. We protect this with an AtomicValue because it is used by reset()
41-
// methods during setup & teardown of tests
62+
/// Special case category. We protect this with an AtomicValue because it is used by reset()
63+
/// methods during setup & teardown of tests
64+
///
65+
/// - Tag: Amplify.Logging
4266
public static internal(set) var Logging: LoggingCategory {
4367
get {
4468
loggingAtomic.get()
@@ -51,7 +75,10 @@ public class Amplify {
5175

5276
/// Adds `plugin` to the category
5377
///
78+
/// See: [Category.removePlugin(for:)](x-source-tag://Category.removePlugin)
79+
///
5480
/// - Parameter plugin: The plugin to add
81+
/// - Tag: Amplify.add_plugin
5582
public static func add<P: Plugin>(plugin: P) throws {
5683
log.debug("Adding plugin: \(plugin))")
5784
switch plugin {

Amplify/Core/Category/Category+Logging.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
public extension Category {
99
/// A default logger for the category
10+
///
11+
/// - Tag: Category.log
1012
var log: Logger {
1113
Amplify.Logging.logger(forCategory: categoryType.displayName)
1214
}

Amplify/Core/Category/Category.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
/// An Amplify Category stores certain global states, holds references to plugins for the category, and routes method
99
/// requests to those plugins appropriately.
10+
///
11+
/// - Tag: Category
1012
public protocol Category: AnyObject, CategoryTypeable, DefaultLogger {
1113

1214
// NOTE: `add(plugin:)` and `getPlugin(for key:)` must be implemented in the actual category classes, since they
@@ -15,7 +17,10 @@ public protocol Category: AnyObject, CategoryTypeable, DefaultLogger {
1517
/// Removes the plugin registered for `key` from the list of Plugins that implement functionality for this category.
1618
/// If no plugin has been added for `key`, no action is taken, making this method safe to call multiple times.
1719
///
20+
/// See: [Amplify.add(plugin:)](x-source-tag://Amplify.add_plugin)
21+
///
1822
/// - Parameter key: The key used to `add` the plugin
23+
/// - Tag: Category.removePlugin
1924
func removePlugin(for key: PluginKey)
2025

2126
}

Amplify/Core/Category/CategoryType.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,72 @@
77

88
/// The Amplify category with which the conforming type is associated. Categories, Plugins, ClientBehaviors, etc must
99
/// all share the same CategoryType
10+
///
11+
/// - Tag: CategoryTypeable
1012
public protocol CategoryTypeable {
13+
/// - Tag: CategoryTypeable.categoryType
1114
var categoryType: CategoryType { get }
1215
}
1316

1417
/// Amplify supports these Category types
18+
///
19+
/// - Tag: CategoryType
1520
public enum CategoryType: String {
1621
/// Record app metrics and analytics data
22+
///
23+
/// - Tag: CategoryType.analytics
1724
case analytics
1825

1926
/// Retrieve data from a remote service
27+
///
28+
/// - Tag: CategoryType.api
2029
case api
2130

2231
/// Authentication
32+
///
33+
/// - Tag: CategoryType.auth
2334
case auth
2435

2536
/// Persist data
37+
///
38+
/// - Tag: CategoryType.dataStore
2639
case dataStore
2740

2841
/// Interact with geospatial services
42+
///
43+
/// - Tag: CategoryType.geo
2944
case geo
3045

3146
/// Listen for or dispatch Amplify events
47+
///
48+
/// - Tag: CategoryType.hub
3249
case hub
3350

3451
/// Log Amplify and app messages
52+
///
53+
/// - Tag: CategoryType.logging
3554
case logging
3655

3756
/// Prediction
57+
///
58+
/// - Tag: CategoryType.predictions
3859
case predictions
3960

4061
/// Push Notifications
62+
///
63+
/// - Tag: CategoryType.pushNotifications
4164
case pushNotifications
4265

4366
/// Upload and download files from the cloud
67+
///
68+
/// - Tag: CategoryType.storage
4469
case storage
4570
}
4671

4772
extension CategoryType: CaseIterable {}
4873

4974
public extension CategoryType {
75+
/// - Tag: CategoryType.displayName
5076
var displayName: String {
5177
switch self {
5278
case .analytics:
@@ -72,6 +98,7 @@ public extension CategoryType {
7298
}
7399
}
74100

101+
/// - Tag: CategoryType.category
75102
var category: Category {
76103
switch self {
77104
case .analytics:

Amplify/Core/Configuration/AmplifyConfiguration.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88
import Foundation
99

10-
/// Configures the Amplify system with sub-configurations for each supported category
10+
/// Represents Amplify's configuration for all categories intended to be used in an application.
11+
///
12+
/// See: [Amplify.configure](x-source-tag://Amplify.configure)
13+
///
14+
/// - Tag: AmplifyConfiguration
1115
public struct AmplifyConfiguration: Codable {
1216
enum CodingKeys: String, CodingKey {
1317
case analytics
@@ -52,6 +56,7 @@ public struct AmplifyConfiguration: Codable {
5256
/// Configurations for the Amplify Storage category
5357
let storage: StorageCategoryConfiguration?
5458

59+
/// - Tag: Amplify.init
5560
public init(analytics: AnalyticsCategoryConfiguration? = nil,
5661
api: APICategoryConfiguration? = nil,
5762
auth: AuthCategoryConfiguration? = nil,
@@ -75,6 +80,8 @@ public struct AmplifyConfiguration: Codable {
7580
}
7681

7782
/// Initialize `AmplifyConfiguration` by loading it from a URL representing the configuration file.
83+
///
84+
/// - Tag: Amplify.configureWithConfigurationFile
7885
public init(configurationFile url: URL) throws {
7986
self = try AmplifyConfiguration.loadAmplifyConfiguration(from: url)
8087
}
@@ -100,6 +107,8 @@ extension Amplify {
100107
/// event to each Amplify Hub channel. After this point, plugins may invoke calls on other Amplify categories.
101108
///
102109
/// - Parameter configuration: The AmplifyConfiguration for specified Categories
110+
///
111+
/// - Tag: Amplify.configure
103112
public static func configure(_ configuration: AmplifyConfiguration? = nil) throws {
104113
log.info("Configuring")
105114
log.debug("Configuration: \(String(describing: configuration))")

Amplify/Core/Configuration/CategoryConfiguration.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
//
77

88
/// A CategoryConfiguration must contain a plugins field used to configure plugins for that category
9+
///
10+
/// - Tag: CategoryConfiguration
911
public protocol CategoryConfiguration: Codable {
1012
/// A map of category plugin configurations by PluginKey. Such configurations are defined by the plugins
1113
/// themselves, and may be of any type.
14+
///
15+
/// - Tag: CategoryConfiguration.plugins
1216
var plugins: [String: JSONValue] { get }
1317
}

Amplify/Core/Configuration/ConfigurationError.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,34 @@
66
//
77

88
/// Errors associated with configuring and inspecting Amplify Categories
9+
///
10+
/// See: [Amplify.configure](x-source-tag://Amplify.configure)
11+
///
12+
/// - Tag: ConfigurationError
913
public enum ConfigurationError {
1014
/// The client issued a subsequent call to `Amplify.configure` after the first had already succeeded
15+
///
16+
/// - Tag: ConfigurationError.amplifyAlreadyConfigured
1117
case amplifyAlreadyConfigured(ErrorDescription, RecoverySuggestion, Error? = nil)
1218

1319
/// The specified `amplifyconfiguration.json` file was not present or unreadable
20+
///
21+
/// - Tag: ConfigurationError.invalidAmplifyConfigurationFile
1422
case invalidAmplifyConfigurationFile(ErrorDescription, RecoverySuggestion, Error? = nil)
1523

1624
/// Unable to decode `amplifyconfiguration.json` into a valid AmplifyConfiguration object
25+
///
26+
/// - Tag: ConfigurationError.unableToDecode
1727
case unableToDecode(ErrorDescription, RecoverySuggestion, Error? = nil)
1828

1929
/// An unknown error occurred
30+
///
31+
/// - Tag: ConfigurationError.unknown
2032
case unknown(ErrorDescription, RecoverySuggestion, Error?)
2133
}
2234

2335
extension ConfigurationError: AmplifyError {
36+
/// - Tag: ConfigurationError.errorDescription
2437
public var errorDescription: ErrorDescription {
2538
switch self {
2639
case .amplifyAlreadyConfigured(let description, _, _),
@@ -31,6 +44,7 @@ extension ConfigurationError: AmplifyError {
3144
}
3245
}
3346

47+
/// - Tag: ConfigurationError.recoverySuggestion
3448
public var recoverySuggestion: RecoverySuggestion {
3549
switch self {
3650
case .amplifyAlreadyConfigured(_, let recoverySuggestion, _),
@@ -41,6 +55,7 @@ extension ConfigurationError: AmplifyError {
4155
}
4256
}
4357

58+
/// - Tag: ConfigurationError.underlyingError
4459
public var underlyingError: Error? {
4560
switch self {
4661
case .amplifyAlreadyConfigured(_, _, let underlyingError),
@@ -51,6 +66,7 @@ extension ConfigurationError: AmplifyError {
5166
}
5267
}
5368

69+
/// - Tag: ConfigurationError.init
5470
public init(
5571
errorDescription: ErrorDescription = "An unknown error occurred",
5672
recoverySuggestion: RecoverySuggestion = "See `underlyingError` for more details",

Amplify/Core/Error/CoreError.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@
66
//
77

88
/// Errors associated with operations provided by Amplify
9+
///
10+
/// - Tag: CoreError
911
public enum CoreError {
1012

1113
/// A related operation performed on `List` resulted in an error.
14+
///
15+
/// - Tag: CoreError.listOperation
1216
case listOperation(ErrorDescription, RecoverySuggestion, Error? = nil)
1317

1418
/// A client side validation error occured.
19+
///
20+
/// - Tag: CoreError.clientValidation
1521
case clientValidation(ErrorDescription, RecoverySuggestion, Error? = nil)
1622
}
1723

1824
extension CoreError: AmplifyError {
25+
/// - Tag: CoreError.errorDescription
1926
public var errorDescription: ErrorDescription {
2027
switch self {
2128
case .listOperation(let errorDescription, _, _),
@@ -24,6 +31,7 @@ extension CoreError: AmplifyError {
2431
}
2532
}
2633

34+
/// - Tag: CoreError.recoverySuggestion
2735
public var recoverySuggestion: RecoverySuggestion {
2836
switch self {
2937
case .listOperation(_, let recoverySuggestion, _),
@@ -32,6 +40,7 @@ extension CoreError: AmplifyError {
3240
}
3341
}
3442

43+
/// - Tag: CoreError.underlyingError
3544
public var underlyingError: Error? {
3645
switch self {
3746
case .listOperation(_, _, let underlyingError),
@@ -40,6 +49,7 @@ extension CoreError: AmplifyError {
4049
}
4150
}
4251

52+
/// - Tag: CoreError.init
4353
public init(
4454
errorDescription: ErrorDescription = "An unknown error occurred",
4555
recoverySuggestion: RecoverySuggestion = "(Ignored)",

0 commit comments

Comments
 (0)