Skip to content

Commit e013047

Browse files
authored
doc: added tutorials for common strategies
1 parent 2ebadd5 commit e013047

27 files changed

Lines changed: 441 additions & 48 deletions

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Supercharge `Swift`'s `Codable` implementations with macros.
1414

1515
## Overview
1616

17-
`MetaCodable` framework exposes custom macros which can be used to generate dynamic `Codable` implementations. The core of the framework is ``Codable()`` macro which generates the implementation aided by data provided with using other macros.
17+
`MetaCodable` framework exposes custom macros which can be used to generate dynamic `Codable` implementations. The core of the framework is ``Codable(commonStrategies:)`` macro which generates the implementation aided by data provided with using other macros.
1818

1919
`MetaCodable` aims to supercharge your `Codable` implementations by providing these inbox features:
2020

@@ -24,6 +24,7 @@ Supercharge `Swift`'s `Codable` implementations with macros.
2424
- Allows to read data from additional fallback `CodingKey`s provided with ``CodedAs(_:_:)``.
2525
- Allows to provide default value in case of decoding failures with ``Default(_:)``, or only in case of failures when missing value with ``Default(ifMissing:)``. Different default values can also be used for value missing and other errors respectively with ``Default(ifMissing:forErrors:)``.
2626
- Allows to create custom decoding/encoding strategies with ``HelperCoder`` and using them with ``CodedBy(_:)``, ``CodedBy(_:properties:)`` or others. i.e. ``LossySequenceCoder`` etc.
27+
- Allows applying common strategies like `ValueCoder` to all properties of a type through the ``Codable(commonStrategies:)`` parameter, reducing the need for repetitive property annotations.
2728
- Allows specifying different case values with ``CodedAs(_:_:)`` and case value/protocol type identifier type different from `String` with ``CodedAs()``.
2829
- Allows specifying enum-case/protocol type identifier path with ``CodedAt(_:)`` and case content path with ``ContentAt(_:_:)``.
2930
- Allows decoding/encoding enums that lack distinct identifiers for each case data with ``UnTagged()``.

Sources/MetaCodable/Codable/Codable.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ public macro Codable(commonStrategies: [CodableCommonStrategy] = []) =
6767

6868
/// Indicates whether super class conforms to `Codable` or not.
6969
///
70-
/// By default, ``Codable()`` assumes class inherits `Decodable`
70+
/// By default, ``Codable(commonStrategies:)`` assumes class inherits `Decodable`
7171
/// or `Encodable` conformance if it doesn't receive protocol needs
7272
/// to be conformed from the compiler. Using this macro, it can be explicitly
7373
/// indicated that the class doesn't inherit conformance in such cases.
7474
///
75-
/// Following code indicates ``Codable()`` that `Item` class doesn't
75+
/// Following code indicates ``Codable(commonStrategies:)`` that `Item` class doesn't
7676
/// inherit conformance:
7777
/// ```swift
7878
/// @Codable
@@ -91,7 +91,7 @@ public macro Codable(commonStrategies: [CodableCommonStrategy] = []) =
9191
/// - encodable: Whether super class conforms to `Encodable`.
9292
///
9393
/// - Note: This macro on its own only validates if attached declaration
94-
/// is a class declaration. ``Codable()`` macro uses this macro
94+
/// is a class declaration. ``Codable(commonStrategies:)`` macro uses this macro
9595
/// when generating final implementations.
9696
@attached(peer)
9797
@available(swift 5.9)

Sources/MetaCodable/Codable/CodingKeys.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/// let description: String
2626
/// }
2727
/// ```
28-
/// The ``Codable()`` macro generated code will transform field names
28+
/// The ``Codable(commonStrategies:)`` macro generated code will transform field names
2929
/// to snake-case in the `Codable` implementation.
3030
///
3131
/// Similarly, for enums associated value label can be kept camel-cased while
@@ -88,10 +88,10 @@
8888
/// ``CodedAt(_:)`` will remain unchanged.
8989
///
9090
/// - Note: This macro on its own only validates if attached declaration
91-
/// is a variable declaration. ``Codable()`` macro uses this macro
91+
/// is a variable declaration. ``Codable(commonStrategies:)`` macro uses this macro
9292
/// when generating final implementations.
9393
///
94-
/// - Important: This attribute must be used combined with ``Codable()``.
94+
/// - Important: This attribute must be used combined with ``Codable(commonStrategies:)``.
9595
///
9696
/// [Swift API Design Guidelines]:
9797
/// https://www.swift.org/documentation/api-design-guidelines/#general-conventions

Sources/MetaCodable/Codable/IgnoreCodingInitialized.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@
5757
/// while `notIgnored` is decoded and encoded.
5858
///
5959
/// - Note: This macro on its own only validates if attached declaration
60-
/// is a variable declaration. ``Codable()`` macro uses this macro
60+
/// is a variable declaration. ``Codable(commonStrategies:)`` macro uses this macro
6161
/// when generating final implementations.
6262
///
63-
/// - Important: This attribute must be used combined with ``Codable()``.
63+
/// - Important: This attribute must be used combined with ``Codable(commonStrategies:)``.
6464
@attached(peer)
6565
@available(swift 5.9)
6666
public macro IgnoreCodingInitialized() =

Sources/MetaCodable/Codable/UnTagged.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
/// variables are successfully decoded, is chosen as the variation case value.
3838
///
3939
/// - Note: This macro on its own only validates if attached declaration
40-
/// is a variable declaration. ``Codable()`` macro uses this macro
40+
/// is a variable declaration. ``Codable(commonStrategies:)`` macro uses this macro
4141
/// when generating final implementations.
4242
///
4343
/// - Important: This macro can only be applied to enums.

Sources/MetaCodable/CodedAs.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/// - Parameter values: The values to use.
4141
///
4242
/// - Note: This macro on its own only validates if attached declaration
43-
/// is a variable declaration. ``Codable()`` macro uses this macro
43+
/// is a variable declaration. ``Codable(commonStrategies:)`` macro uses this macro
4444
/// when generating final implementations.
4545
///
4646
/// - Important: The value type must be `String` when used in
@@ -103,7 +103,7 @@ public macro CodedAs<T: Codable & Equatable>(_ values: T, _: T...) =
103103
/// ```
104104
///
105105
/// - Note: This macro on its own only validates if attached declaration
106-
/// is a variable declaration. ``Codable()`` macro uses this macro
106+
/// is a variable declaration. ``Codable(commonStrategies:)`` macro uses this macro
107107
/// when generating final implementations.
108108
///
109109
/// - Important: For each case ``CodedAs(_:_:)`` macro with values
@@ -116,7 +116,7 @@ public macro CodedAs<T: Codable & Equatable>(_ values: T, _: T...) =
116116
/// type must be same as the type defined with this macro, in absence of this macro
117117
/// ``DynamicCodable/IdentifierValue`` type must be `String`.
118118
///
119-
/// - Important: This attribute must be used combined with ``Codable()``
119+
/// - Important: This attribute must be used combined with ``Codable(commonStrategies:)``
120120
/// and ``CodedAt(_:)``.
121121
@attached(peer)
122122
@available(swift 5.9)

Sources/MetaCodable/CodedAt.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
/// - Parameter path: The `CodingKey` path value located at.
125125
///
126126
/// - Note: This macro on its own only validates if attached declaration
127-
/// is a variable declaration. ``Codable()`` macro uses this macro
127+
/// is a variable declaration. ``Codable(commonStrategies:)`` macro uses this macro
128128
/// when generating final implementations.
129129
///
130130
/// - Important: When applied to fields, the field type must confirm to

Sources/MetaCodable/CodedBy.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// - Parameter helper: The value that performs decoding and encoding.
1515
///
1616
/// - Note: This macro on its own only validates if attached declaration
17-
/// is a variable declaration. ``Codable()`` macro uses this macro
17+
/// is a variable declaration. ``Codable(commonStrategies:)`` macro uses this macro
1818
/// when generating final implementations.
1919
///
2020
/// - Important: The `helper`'s ``HelperCoder/Coded``
@@ -23,7 +23,7 @@
2323
/// - Important: When using with enums and protocols if ``HelperCoder/Coded``
2424
/// is other than `String` type must be provided with ``CodedAs()`` macro.
2525
///
26-
/// - Important: This attribute must be used combined with ``Codable()``
26+
/// - Important: This attribute must be used combined with ``Codable(commonStrategies:)``
2727
/// and ``CodedAt(_:)`` when applying to enums/protocols.
2828
@attached(peer)
2929
@available(swift 5.9)
@@ -73,7 +73,7 @@ public macro CodedBy<T: HelperCoder>(_ helper: T) =
7373
/// - properties: The key path to properties passed to the creation action.
7474
///
7575
/// - Note: This macro on its own only validates if attached declaration
76-
/// is a variable declaration. ``Codable()`` macro uses this macro
76+
/// is a variable declaration. ``Codable(commonStrategies:)`` macro uses this macro
7777
/// when generating final implementations.
7878
///
7979
/// - Important: The `Parent` type must be the current `struct`/`class`/`actor`
@@ -139,7 +139,7 @@ public macro CodedBy<Parent, Helper: HelperCoder, each Property>(
139139
/// - properties: The key path to properties passed to the creation action.
140140
///
141141
/// - Note: This macro on its own only validates if attached declaration
142-
/// is a variable declaration. ``Codable()`` macro uses this macro
142+
/// is a variable declaration. ``Codable(commonStrategies:)`` macro uses this macro
143143
/// when generating final implementations.
144144
///
145145
/// - Important: The `Parent` type must be the current `struct`/`class`/`actor`
@@ -166,7 +166,7 @@ public macro CodedBy<Parent, Helper: HelperCoder, each Argument, each Property>(
166166
/// - properties: The key path to properties passed to the creation action.
167167
///
168168
/// - Note: This macro on its own only validates if attached declaration
169-
/// is a variable declaration. ``Codable()`` macro uses this macro
169+
/// is a variable declaration. ``Codable(commonStrategies:)`` macro uses this macro
170170
/// when generating final implementations.
171171
///
172172
/// - Important: The `Parent` type must be the current `struct`/`class`/`actor`
@@ -196,7 +196,7 @@ public macro CodedBy<Parent, Helper: HelperCoder, Argument1, each Property>(
196196
/// - properties: The key path to properties passed to the creation action.
197197
///
198198
/// - Note: This macro on its own only validates if attached declaration
199-
/// is a variable declaration. ``Codable()`` macro uses this macro
199+
/// is a variable declaration. ``Codable(commonStrategies:)`` macro uses this macro
200200
/// when generating final implementations.
201201
///
202202
/// - Important: The `Parent` type must be the current `struct`/`class`/`actor`
@@ -229,7 +229,7 @@ public macro CodedBy<
229229
/// - properties: The key path to properties passed to the creation action.
230230
///
231231
/// - Note: This macro on its own only validates if attached declaration
232-
/// is a variable declaration. ``Codable()`` macro uses this macro
232+
/// is a variable declaration. ``Codable(commonStrategies:)`` macro uses this macro
233233
/// when generating final implementations.
234234
///
235235
/// - Important: The `Parent` type must be the current `struct`/`class`/`actor`

Sources/MetaCodable/CodedIn.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/// - Parameter path: The `CodingKey` path of container value located in.
3232
///
3333
/// - Note: This macro on its own only validates if attached declaration
34-
/// is a variable declaration. ``Codable()`` macro uses this macro
34+
/// is a variable declaration. ``Codable(commonStrategies:)`` macro uses this macro
3535
/// when generating final implementations.
3636
///
3737
/// - Note: Providing no arguments has the same effect as not applying

Sources/MetaCodable/ContentAt.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
/// protocol conforming type data located at.
4848
///
4949
/// - Note: This macro on its own only validates if attached declaration
50-
/// is a variable declaration. ``Codable()`` macro uses this macro
50+
/// is a variable declaration. ``Codable(commonStrategies:)`` macro uses this macro
5151
/// when generating final implementations.
5252
///
53-
/// - Important: This attribute must be used combined with ``Codable()``
53+
/// - Important: This attribute must be used combined with ``Codable(commonStrategies:)``
5454
/// and ``CodedAt(_:)``.
5555
@attached(peer)
5656
@available(swift 5.9)

0 commit comments

Comments
 (0)