Protocol
ParentCodableDynamicDispatch
public protocol ParentCodableDynamicDispatch
ParentCodableDynamicDispatch is a weakly typed wrapper to dispatch wrap method calls to a ParentCodable object.
This protocol is a solution for the Swift limitation of protocols with associated types only being usable for generic constraints.
Example demonstrating the is operator usage issue:
// Error: Protocol 'ParentCodable' can only be used as a generic
// constraint because it has Self or associated type requirements.
if someCodable is ParentCodable {
...
}
// Solution:
if someParentCodable is ParentCodableDynamicDispatch {
...
}
Example demonstrating the wrap(child: ChildCodable) usage issue:
// Error: Protocol 'ParentCodable' can only be used as a generic
// constraint because it has Self or associated type requirements.
if let someParentCodableType = someCodableType as? ParentCodable.Type {
someParentCodableType.wrap(child: someChildCodable)
}
// Solution:
if let someParentCodableType = someCodableType as? ParentCodableDynamicDispatch.Type {
someParentCodableType.dynamicWrap(child: someChildCodable)
}
Relationships
Types Conforming to ParentCodableDynamicDispatch
ParentCodableA type that can wrap a child Codable value into a representation of itself.
Requirements
dynamicWrap(child:)
static func dynamicWrap(child: Any) -> Any
Should delegate the call and child value to a strongly typed
ParentCodable.wrap(child: ChildCodable) implementation.
Parameters
| Name | Type | Description |
|---|---|---|
| child | Any |
The value to be wrapped by a parent type implementing this protocol implicitly using |
Returns
An instance of the parent type wrapping the child value.