State
-
A convienence type for the application state to adhere to.
Declaration
Swift
@available(*, deprecated) public typealias StateType = Codable & Equatable
-
A type of state that can be identified for tracking purposes.
This is typically used for entities stored in your state that might be accessed by id or displayed in a
See moreList
view.Declaration
Swift
@available(*, deprecated, message: "Use Identifiable instead.") public protocol IdentifiableState : Decodable, Encodable, Equatable, Identifiable where Self.ID : Decodable, Self.ID : Encodable
-
A container state that holds an ordered collection of substates.
It’s a common requirement to store a collection of substates. For example, a list of entities retrieved from a service. For an optimal solution, you typically require a lookup table of entity states by their ids. However, you also need an ordered array to display those entities in a list to the user. You end up managing both a dictionary of entities and an ordered array of their ids. This struct manages that responsibility for you. It also provides conveniences for direct use by SwiftUI
List
views.
See morevar todos: OrderedState<TodoState> = ... // When a user adds a new todo: todos.append(todo) // When a user deletes multiple todos todos.delete(at: indexSet) // Using the OrderedState with a list view. var body: some View { List { ForEach(todos) { } .onDelete { todos.delete(at: $0 } .onMove { todos.move(from: $0, to: $1 } } }
Declaration
Swift
public struct OrderedState<Substate> where Substate : Identifiable
extension OrderedState: MutableCollection
extension OrderedState: RandomAccessCollection
extension OrderedState: Equatable where Substate: Equatable
extension OrderedState: Decodable where Substate: Decodable
extension OrderedState: Encodable where Substate: Encodable