AnyDifferentiable
public struct AnyDifferentiable : Differentiable
A type-erased differentiable value.
The AnyDifferentiable
type hides the specific underlying types.
DifferenceIdentifier
type is erased by AnyHashable
.
The comparisons of whether has updated is forwards to an underlying differentiable value.
You can store mixed-type elements in collection that require Differentiable
conformance by
wrapping mixed-type elements in AnyDifferentiable
:
extension String: Differentiable {}
extension Int: Differentiable {}
let source = [
AnyDifferentiable("ABC"),
AnyDifferentiable(100)
]
let target = [
AnyDifferentiable("ABC"),
AnyDifferentiable(100),
AnyDifferentiable(200)
]
let changeset = StagedChangeset(source: source, target: target)
print(changeset.isEmpty) // prints "false"
-
The value wrapped by this instance.
Declaration
Swift
public let base: Any
-
A type-erased identifier value for difference calculation.
Declaration
Swift
public let differenceIdentifier: AnyHashable
-
Creates a type-erased differentiable value that wraps the given instance.
Declaration
Swift
public init<D>(_ base: D) where D : Differentiable
Parameters
base
A differentiable value to wrap.
-
Declaration
Swift
public var debugDescription: String { get }