AnyDifferentiable
public struct AnyDifferentiable : Differentiable
A type-erased differentiable value.
The AnyDifferentiable
type hides the specific underlying types.
Associated type DifferenceIdentifier
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
@inlinable public var base: Any { get }
-
A type-erased identifier value for difference calculation.
Declaration
Swift
@inlinable public var differenceIdentifier: AnyHashable { get }
-
Creates a type-erased differentiable value that wraps the given instance.
Declaration
Swift
@inlinable public init<D>(_ base: D) where D : Differentiable
Parameters
base
A differentiable value to wrap.
-
Indicate whether the content of
base
is equals to the content of the given source value.Declaration
Swift
@inlinable public func isContentEqual(to source: AnyDifferentiable) -> Bool
Parameters
source
A source value to be compared.
-
Declaration
Swift
public var debugDescription: String { get }