RestfulPropertyKit Documentation Beta

Protocol Parent​Codable​Dynamic​Dispatch

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)
}
ParentCodableDynamicDispatch ParentCodableDynamicDispatch ParentCodable ParentCodable ParentCodable->ParentCodableDynamicDispatch

Types Conforming to Parent​Codable​Dynamic​Dispatch

ParentCodable

A type that can wrap a child Codable value into a representation of itself.

Requirements

dynamic​Wrap(child:​)

static func dynamicWrap(child: Any) -> Any

Should delegate the call and child value to a strongly typed ParentCodable.wrap(child: ChildCodable) implementation.

Parameters

child Any

The value to be wrapped by a parent type implementing this protocol implicitly using ParentCodable.

Returns

An instance of the parent type wrapping the child value.