Skip to content

Commit 4d09bb0

Browse files
committed
Describe how to exclude declarations from being picked up by ASTDecodable
1 parent 2ebdac3 commit 4d09bb0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Sources/LiveViewNative/LiveViewNative.docc/AddCustomModifier.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,42 @@ labeled(as: 5)
112112
labeled(as: "Label")
113113
```
114114

115+
``ASTDecodable(_:options:)`` will also synthesize decoders for enum cases, static functions, static members, properties, and member functions.
116+
To exclude any of these declarations from the decoder, either prefix them with an underscore (`_`), or define them in an extension.
117+
Static functions, static members, properties, and member functions will only receive a synthesized decoder if they return `Self` (or a type name that matches the declaration ``ASTDecodable(_:options:)`` is attached to).
118+
119+
```swift
120+
@ASTDecodable("MyType")
121+
enum MyType: Decodable {
122+
init() {} // decodable
123+
124+
case enumCase // decodable
125+
126+
static func staticFunction() -> Self { ... } // decodable
127+
static func staticFunction() -> OtherType { ... } // not decodable
128+
static func _staticFunction() -> OtherType { ... } // not decodable
129+
130+
static var staticMember: Self { ... } // decodable
131+
static var staticMember: OtherType { ... } // not decodable
132+
static var _staticMember: OtherType { ... } // not decodable
133+
134+
func memberFunction() -> Self { ... } // decodable
135+
func memberFunction() -> OtherType { ... } // not decodable
136+
func _memberFunction() -> OtherType { ... } // not decodable
137+
138+
var property: Self { ... } // decodable
139+
var property: OtherType { ... } // not decodable
140+
var _property: OtherType { ... } // not decodable
141+
}
142+
143+
extension MyType {
144+
static func staticFunction() -> Self { ... } // not decodable
145+
static var staticMember: Self { ... } // not decodable
146+
func memberFunction() -> Self { ... } // not decodable
147+
var property: Self { ... } // not decodable
148+
}
149+
```
150+
115151
### Attribute References
116152
Any type that conforms to ``AttributeDecodable`` can be wrapped with ``AttributeReference``.
117153

0 commit comments

Comments
 (0)