Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Examples/SwiftUIExample/AppSpiceStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ final class AppSpiceStore: SpiceStore {
}
.padding()
@Spice var version = LabeledContent("Version", value: "1.0 (1)")
@Spice var userId: String = "Not loaded"

func onAppear() {
userId = "\(Int.random(in: 0...100))"
}
}

final class DebuggingSpiceStore: SpiceStore {
Expand Down
5 changes: 5 additions & 0 deletions Examples/UIKitExample/AppSpiceStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ final class AppSpiceStore: SpiceStore {
}
.padding()
@Spice var version = LabeledContent("Version", value: "1.0 (1)")
@Spice var userId: String = "Not loaded"

private init() {}

func onAppear() {
userId = "\(Int.random(in: 0...100))"
}
}

final class DebuggingSpiceStore: SpiceStore {
Expand Down
3 changes: 3 additions & 0 deletions Sources/Spices/SpiceEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public struct SpiceEditor: View {
MenuItemListView(items: spiceStore.menuItems, title: title) {
dismiss()
}
.onAppear {
spiceStore.onAppear()
}
}
.configureSheetPresentation()
.environmentObject(UserInteraction())
Expand Down
6 changes: 6 additions & 0 deletions Sources/Spices/SpiceStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ public protocol SpiceStore: AnyObject, ObservableObject {
///
/// The default implementation returns `UserDefaults.standard`.
var userDefaults: UserDefaults { get }

/// Call when the store appear on the screen
func onAppear()
}

public extension SpiceStore {
var userDefaults: UserDefaults {
.standard
}

func onAppear() {
}
}

public extension SpiceStore {
Expand Down