State

public struct State

Structure that represents the store state. The store state is kept as a Dictionary with String Keys and Any Values ([String: Any])

For example, the state with two struct looks like:

[
  "TodoItems": TodoItems(....),
  "AppSettings": AppSettings(....)
]
  • Initialize a state with a dictionary

    Declaration

    Swift

    public init(dictionary: [StateKey: Any])

    Parameters

    dictionary

    the dictionary to initialize the state with

  • Get a value for a key

    Declaration

    Swift

    public subscript(key: String) -> Any?

    Parameters

    key

    the key to get the value for.

  • Get a value for a key

    Declaration

    Swift

    public func value(forKey key: String) -> Any?

    Parameters

    key

    the key to get the value for

    Return Value

    the state value for the key if found

  • Get a value for a key of specific type

    Declaration

    Swift

    public func value<Type>(forKeyOfType type: Type.Type) -> Type?

    Parameters

    type

    the type to use for casting and fetching the state key

    Return Value

    if the key is found and if its of the passed type then return it. Otherwise return nil.

  • Get a value for a key of specific type

    Declaration

    Swift

    public func value<Type>(forKey key: String, ofType type: Type.Type) -> Type?

    Parameters

    key

    the key to get the value for

    type

    the type to cast the state to

    Return Value

    if the key is found and if its of the passed type then return it. Otherwise return nil.

  • Return all the keys in the state.

    Declaration

    Swift

    public var keys: [StateKey]
  • Initialize a State with a dictionary literal

    Declaration

    Swift

    public init(dictionaryLiteral elements: (StateKey, Any)...)

    Parameters

    elements

    the dictionary literal to initialzie the StoreSate