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
dictionarythe dictionary to initialize the state with
-
Get a value for a key
Declaration
Swift
public subscript(key: String) -> Any?Parameters
keythe key to get the value for.
-
Get a value for a key
Declaration
Swift
public func value(forKey key: String) -> Any?Parameters
keythe 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
typethe 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
keythe key to get the value for
typethe 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
elementsthe dictionary literal to initialzie the StoreSate
View on GitHub
State Struct Reference