Skip to content

Commit 3f87100

Browse files
authored
doc: added tutorials for helper and dynamic decoding/encoding (#64)
1 parent 5a91b99 commit 3f87100

File tree

124 files changed

+1498
-42
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+1498
-42
lines changed

.github/config/spellcheck-wordlist.txt

+6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ HelperCoders
99
JSON
1010
LossySequenceCoder
1111
Codable
12+
Encodable
13+
Decodable
1214
MetaCodable
15+
MetaProtocolCodable
1316
Midbin
1417
README
1518
Refactorings
@@ -56,3 +59,6 @@ enums
5659
conformances
5760
Podfile
5861
cocoapods
62+
DocumentationExtension
63+
mergeBehavior
64+
lowercasing

Sources/HelperCoders/Base64Coder.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22
import MetaCodable
33

4-
/// An ``/MetaCodable/HelperCoder`` that helps decoding/encoding
4+
/// An `HelperCoder` that helps decoding/encoding
55
/// base64 data.
66
///
77
/// This type can be used to decode/encode base64 data
@@ -12,7 +12,7 @@ public struct Base64Coder: HelperCoder {
1212
/// The options to use when encoding data.
1313
private let encodeOptions: Data.Base64EncodingOptions
1414

15-
/// Creates a new instance of ``/MetaCodable/HelperCoder`` that decodes/encodes
15+
/// Creates a new instance of `HelperCoder` that decodes/encodes
1616
/// base64 data.
1717
///
1818
/// - Parameters:

Sources/HelperCoders/ConditionalCoder.swift

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,76 @@
11
import MetaCodable
22

3-
/// An ``/MetaCodable/HelperCoder`` that helps decoding/encoding
4-
/// with two separate ``/MetaCodable/HelperCoder``s.
3+
/// An `HelperCoder` that helps decoding/encoding
4+
/// with two separate `HelperCoder`s.
55
///
6-
/// This type can be used to use separate ``/MetaCodable/HelperCoder``s
6+
/// This type can be used to use separate `HelperCoder`s
77
/// for decoding and encoding.
88
public struct ConditionalCoder<D: HelperCoder, E: HelperCoder>: HelperCoder
99
where D.Coded == E.Coded {
10-
/// The ``/MetaCodable/HelperCoder`` used for decoding.
10+
/// The `HelperCoder` used for decoding.
1111
@usableFromInline
1212
internal let decoder: D
13-
/// The ``/MetaCodable/HelperCoder`` used for encoding.
13+
/// The `HelperCoder` used for encoding.
1414
@usableFromInline
1515
internal let encoder: E
1616

17-
/// Creates a new instance of ``/MetaCodable/HelperCoder`` that decodes/encodes
17+
/// Creates a new instance of `HelperCoder` that decodes/encodes
1818
/// conditionally with provided decoder/encoder respectively.
1919
///
2020
/// The provided decoder is used only for decoding
2121
/// and encoder only for encoding.
2222
///
2323
/// - Parameters:
24-
/// - decoder: The ``/MetaCodable/HelperCoder`` used for decoding.
25-
/// - encoder: The ``/MetaCodable/HelperCoder`` used for encoding.
24+
/// - decoder: The `HelperCoder` used for decoding.
25+
/// - encoder: The `HelperCoder` used for encoding.
2626
public init(decoder: D, encoder: E) {
2727
self.decoder = decoder
2828
self.encoder = encoder
2929
}
3030

31-
/// Decodes using the decode specific ``/MetaCodable/HelperCoder``
31+
/// Decodes using the decode specific `HelperCoder`
3232
/// from the given `decoder`.
3333
///
3434
/// - Parameter decoder: The decoder to read data from.
3535
/// - Returns: The decoded value.
36-
/// - Throws: If the underlying ``/MetaCodable/HelperCoder`` throws error.
36+
/// - Throws: If the underlying `HelperCoder` throws error.
3737
@inlinable
3838
public func decode(from decoder: Decoder) throws -> D.Coded {
3939
return try self.decoder.decode(from: decoder)
4040
}
4141

4242
/// Decodes optional value using the decode specific
43-
/// ``/MetaCodable/HelperCoder`` from the given `decoder`.
43+
/// `HelperCoder` from the given `decoder`.
4444
///
4545
/// - Parameter decoder: The decoder to read data from.
4646
/// - Returns: The decoded optional value.
47-
/// - Throws: If the underlying ``/MetaCodable/HelperCoder`` throws error.
47+
/// - Throws: If the underlying `HelperCoder` throws error.
4848
@inlinable
4949
public func decodeIfPresent(from decoder: Decoder) throws -> D.Coded? {
5050
return try self.decoder.decodeIfPresent(from: decoder)
5151
}
5252

53-
/// Encodes using the encode specific ``/MetaCodable/HelperCoder``
53+
/// Encodes using the encode specific `HelperCoder`
5454
/// from the given `encoder`.
5555
///
5656
/// - Parameters:
5757
/// - value: The value to encode.
5858
/// - encoder: The encoder to write data to.
5959
///
60-
/// - Throws: If the underlying ``/MetaCodable/HelperCoder`` throws error.
60+
/// - Throws: If the underlying `HelperCoder` throws error.
6161
@inlinable
6262
public func encode(_ value: E.Coded, to encoder: Encoder) throws {
6363
try self.encoder.encode(value, to: encoder)
6464
}
6565

6666
/// Encodes optional value using the encode specific
67-
/// ``/MetaCodable/HelperCoder`` from the given `encoder`.
67+
/// `HelperCoder` from the given `encoder`.
6868
///
6969
/// - Parameters:
7070
/// - value: The value to encode.
7171
/// - encoder: The encoder to write data to.
7272
///
73-
/// - Throws: If the underlying ``/MetaCodable/HelperCoder`` throws error.
73+
/// - Throws: If the underlying `HelperCoder` throws error.
7474
@inlinable
7575
public func encodeIfPresent(_ value: E.Coded?, to encoder: Encoder) throws {
7676
try self.encoder.encodeIfPresent(value, to: encoder)

Sources/HelperCoders/DateCoders/DateCoder.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import MetaCodable
88
/// represented in **ISO 8601** text format.
99
public typealias ISO8601DateCoder = DateCoder<ISO8601DateFormatter>
1010

11-
/// An ``/MetaCodable/HelperCoder`` that helps decoding/encoding
11+
/// An `HelperCoder` that helps decoding/encoding
1212
/// formatted date representation.
1313
///
1414
/// This type can be used to decode/encode dates
@@ -18,7 +18,7 @@ public struct DateCoder<Formatter: DateFormatConverter>: HelperCoder {
1818
@usableFromInline
1919
internal let formatter: Formatter
2020

21-
/// Creates a new instance of ``/MetaCodable/HelperCoder`` that decodes/encodes
21+
/// Creates a new instance of `HelperCoder` that decodes/encodes
2222
/// formatted date representation.
2323
///
2424
/// Created instance can be used to decode/encode dates
@@ -29,7 +29,7 @@ public struct DateCoder<Formatter: DateFormatConverter>: HelperCoder {
2929
self.formatter = formatter
3030
}
3131

32-
/// Creates a new instance of ``/MetaCodable/HelperCoder`` that decodes/encodes
32+
/// Creates a new instance of `HelperCoder` that decodes/encodes
3333
/// **ISO 8601** formatted date representation.
3434
///
3535
/// Created instance can be used to decode/encode dates

Sources/HelperCoders/DateCoders/Since1970DateCoder.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22
import MetaCodable
33

4-
/// An ``/MetaCodable/HelperCoder`` that helps decoding/encoding
4+
/// An `HelperCoder` that helps decoding/encoding
55
/// UNIX timestamp.
66
///
77
/// This type can be used to decode/encode dates
@@ -47,7 +47,7 @@ public struct Since1970DateCoder: HelperCoder {
4747
@usableFromInline
4848
internal let type: IntervalType
4949

50-
/// Creates a new instance of ``/MetaCodable/HelperCoder`` that decodes/encodes
50+
/// Creates a new instance of `HelperCoder` that decodes/encodes
5151
/// UNIX timestamp.
5252
///
5353
/// Created instance can be used to decode/encode dates

Sources/HelperCoders/HelperCoders.docc/HelperCoders.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@Available(swift, introduced: "5.9")
55
}
66

7-
Level up ``/MetaCodable``'s generated implementations with helpers assisting common decoding/encoding requirements.
7+
Level up `MetaCodable`'s generated implementations with helpers assisting common decoding/encoding requirements.
88

99
## Overview
1010

Sources/HelperCoders/NonConformingCoder.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import MetaCodable
22

3-
/// An ``/MetaCodable/HelperCoder`` that helps decoding/encoding
3+
/// An `HelperCoder` that helps decoding/encoding
44
/// non-confirming floating point values.
55
///
66
/// This type can be used to decode/encode exceptional
@@ -14,7 +14,7 @@ where Float: FloatingPoint & Codable & LosslessStringConvertible {
1414
/// The value representing not-a-number.
1515
private let nan: String
1616

17-
/// Creates a new instance of ``/MetaCodable/HelperCoder`` that decodes/encodes
17+
/// Creates a new instance of `HelperCoder` that decodes/encodes
1818
/// exceptional floating-point values matching provided
1919
/// string representations.
2020
///

Sources/HelperCoders/PropertyWrapperCoder.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import MetaCodable
22

3-
/// An ``/MetaCodable/HelperCoder`` that helps decoding/encoding
3+
/// An `HelperCoder` that helps decoding/encoding
44
/// using existing property wrappers.
55
///
66
/// This type can be used to reuse existing property
77
/// wrappers with custom decoding/encoding with
8-
/// ``/MetaCodable`` generated implementations.
8+
/// `MetaCodable` generated implementations.
99
public struct PropertyWrapperCoder<Wrapper: PropertyWrappable>: HelperCoder {
10-
/// Creates a new instance of ``/MetaCodable/HelperCoder`` that decodes/encodes
10+
/// Creates a new instance of `HelperCoder` that decodes/encodes
1111
/// using existing property wrappers.
1212
///
1313
/// - Returns: A new property wrapper based decoder/encoder.

Sources/HelperCoders/SequenceCoder/DefaultSequenceElementCoding.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import MetaCodable
22

3-
/// An ``/MetaCodable/HelperCoder`` that performs default decoding/encoding.
3+
/// An `HelperCoder` that performs default decoding/encoding.
44
///
55
/// This type doesn't provide any customization and used only to opt out of
66
/// decoding/encoding customizations.

Sources/HelperCoders/SequenceCoder/SequenceCoder.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import MetaCodable
22

3-
/// An ``/MetaCodable/HelperCoder`` that helps decoding/encoding sequence.
3+
/// An `HelperCoder` that helps decoding/encoding sequence.
44
///
55
/// This type tries to decode and encode a sequence according to provided
6-
/// ``Configuration-swift.struct`` and element ``/MetaCodable/HelperCoder``.
6+
/// ``Configuration-swift.struct`` and element `HelperCoder`.
77
///
88
/// `DefaultSequenceElementCoding` can be used as element
9-
/// ``/MetaCodable/HelperCoder``, if on configuration based.
9+
/// `HelperCoder`, if on configuration based.
1010
/// decoding/encoding needed
1111
public struct SequenceCoder<Sequence, ElementHelper>: HelperCoder
1212
where
1313
Sequence: SequenceInitializable, ElementHelper: HelperCoder,
1414
Sequence.Element == ElementHelper.Coded
1515
{
16-
/// The ``/MetaCodable/HelperCoder`` for element.
16+
/// The `HelperCoder` for element.
1717
///
1818
/// Each element is decoded/encoded using this.
1919
public let elementHelper: ElementHelper
@@ -28,7 +28,7 @@ where
2828
///
2929
/// - Parameters:
3030
/// - output: The resulting sequence type.
31-
/// - elementHelper: The ``/MetaCodable/HelperCoder`` for element.
31+
/// - elementHelper: The `HelperCoder` for element.
3232
/// - configuration: The configuration for decoding and encoding.
3333
public init(
3434
output: Sequence.Type, elementHelper: ElementHelper,
@@ -43,7 +43,7 @@ where
4343
/// Sequence type is inferred from provided configuration.
4444
///
4545
/// - Parameters:
46-
/// - elementHelper: The ``/MetaCodable/HelperCoder`` for element.
46+
/// - elementHelper: The `HelperCoder` for element.
4747
/// - configuration: The configuration for decoding and encoding.
4848
public init(
4949
elementHelper: ElementHelper, configuration: Configuration
@@ -92,7 +92,7 @@ where
9292
/// By default, no additional customizations configuration is used.
9393
///
9494
/// - Parameters:
95-
/// - elementHelper: The ``/MetaCodable/HelperCoder`` for element.
95+
/// - elementHelper: The `HelperCoder` for element.
9696
/// - configuration: The configuration for decoding and encoding.
9797
public init(
9898
elementHelper: ElementHelper, configuration: Configuration = .init()

Sources/HelperCoders/ValueCoders/ValueCoder.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import MetaCodable
22

3-
/// An ``/MetaCodable/HelperCoder`` that helps decoding/encoding
3+
/// An `HelperCoder` that helps decoding/encoding
44
/// basic value types.
55
///
66
/// This type can be used to decode/encode dates
77
/// basic value types, i.e. `Bool`, `Int`, `String` etc.
88
public struct ValueCoder<Strategy: ValueCodingStrategy>: HelperCoder {
9-
/// Creates a new instance of ``/MetaCodable/HelperCoder`` that decodes/encodes
9+
/// Creates a new instance of `HelperCoder` that decodes/encodes
1010
/// basic value types.
1111
///
1212
/// - Returns: A new basic value type decoder/encoder.

Sources/MetaCodable/MetaCodable.docc/Limitations.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ enum SomeEnum {
6161
}
6262
```
6363

64-
### Why `enum`s with raw value aren't supported?
64+
### Why enums with raw value aren't supported?
6565

6666
`Swift` compiler by default generates `Codable` conformance for `enum`s with raw value and `MetaCodable` has nothing extra to add for these type of `enum`s. Hence, in this case the default compiler generated implementation can be used.
6767

68-
### Why `actor` conformance to `Encodable` not generated?
68+
### Why actor conformance to Encodable not generated?
6969

7070
For `actor`s ``Codable()`` generates `Decodable` conformance, while `Encodable` conformance isn't generated, only `encode(to:)` method implementation is generated which is isolated to `actor`.
7171

7272
To generate `Encodable` conformance, the `encode(to:)` method must be `nonisolated` to `actor`, and since `encode(to:)` method must be synchronous making it `nonisolated` will prevent accessing mutable properties.
7373

7474
Due to these limitations, `Encodable` conformance isn't generated, users has to implement the conformance manually.
7575

76-
### Why `MetaProtocolCodable` plugin can't scan Xcode target dependencies?
76+
### Why MetaProtocolCodable plugin can't scan Xcode target dependencies?
7777

7878
Currently Swift Package Manager always returns empty list for Xcode target dependencies as noted in [this bug](https://github.com/apple/swift-package-manager/issues/6003). Hence `MetaProtocolCodable` can currently only scan the files from the target or from the project including the target.

Sources/MetaCodable/MetaCodable.docc/MetaCodable.md

+1
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,4 @@ Supercharge `Swift`'s `Codable` implementations with macros.
9595

9696
- ``DynamicCodable``
9797
- ``DynamicCodableIdentifier``
98+
- ``MetaCodableConfig``
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# ``MetaCodableConfig``
2+
3+
@Metadata {
4+
@DocumentationExtension(mergeBehavior: override)
5+
}
6+
7+
The configuration file providing additional customization options for `MetaProtocolCodable` build tool plugin.
8+
9+
## Overview
10+
11+
The data present in this file can be either of `plist` or `json` format. The name of the configuration file can be of any format as long as removing non-alphanumeric characters and lowercasing the name matches `metacodableconfig` text, i.e. following names are supported:
12+
13+
- `MetaCodableConfig.plist`
14+
- `meta_codable_config.json`
15+
- `meta-codable-config.json` etc.
16+
17+
- Important: The file must be added at the target root directory for Swift packages and for Xcode targets the file must be part of the target.
18+
19+
- Tip: The option names/keys provided in this file are also case-insensitive. i.e. `Scan`, `scan`, `SCAN` are all valid option names for ``Scan``.
20+
21+
## Topics
22+
23+
### Options
24+
25+
- ``Scan``
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# ``MetaCodableConfig/Scan``
2+
3+
@Metadata {
4+
@DocumentationExtension(mergeBehavior: override)
5+
}
6+
7+
The source file scan option for `MetaProtocolCodable` build tool plugin.
8+
9+
## Overview
10+
11+
This option can accept any of the following values, depending on which the source files scanned by `MetaProtocolCodable` build tool plugin is controlled:
12+
13+
- `target`: Source files present in the `MetaProtocolCodable` build tool plugin target are scanned rest of the files are ignored.
14+
- `direct`: Source files present in the `MetaProtocolCodable` build tool plugin target and its direct dependencies are scanned rest of the files are ignored.
15+
- `local`: Source files present in the `MetaProtocolCodable` build tool plugin target and only its direct dependencies which are local dependencies are scanned rest of the files are ignored.
16+
- `recursive`: Source files present in the `MetaProtocolCodable` build tool plugin target and all its dependencies are scanned rest of the files are ignored.

0 commit comments

Comments
 (0)