SwiftKit Documentation

Structure Traceable

@propertyWrapper
public struct Traceable<Type>  

Add ability to type to have traceable history. property with this propertyWrapper will automatically have version. if propery is set, the set value will enter history.

example

struct User {
    @Traceable
    var name: String
}

to see more, check Traceable+Tests.swift

Initializers

init(wrapped​Value:​max​Size:​)

public init(wrappedValue: Type, maxSize: Int = 50)  

Properties

wrapped​Value

public var wrappedValue: Type  

Methods

revert()

public mutating func revert()  

Remove last history

checkout(_:​)

public mutating func checkout(_ cursor: Int)  

Move cursor to spesific index

Parameters

cursor Int

index of history

flush()

public mutating func flush()  

Remove all history, and left 1 last element

first()

public func first() -> Type?  

Get first history

Returns

First history

first(where:​)

public func first(where predicate: (Type) throws -> Bool) rethrows -> Type?  

Get first item that meet condition

Parameters

predicate (Type) throws -> Bool

Condition, if true, will return spesific history

Returns

History that meet given condition

last()

public func last() -> Type?  

Get last history

Returns

Last history

last(where:​)

public func last(where predicate: (Type) throws -> Bool) rethrows -> Type?  

Get last item that meet condition

Parameters

predicate (Type) throws -> Bool

Condition, if true, will return spesific history

Returns

History that meet given condition

all()

public func all() -> [Type]  

Get all version

Returns

All version on current value