Replies: 2 comments 2 replies
-
From my debugging, it appears that the cast on this line is failing. The
|
Beta Was this translation helpful? Give feedback.
1 reply
-
I'm afraid I'm going to need you to provide a minimum viable project that demonstrates the issue. I added the following to FactoryDemo import Factory
import SwiftUI
struct ModelTest: View {
var modelData: ModelData
var body: some View {
Text("Debug: \(modelData.games.count)")
}
}
#Preview {
Container.shared.modelData.reset(.scope)
let modelData = Container.shared.modelData()
return ModelTest(modelData: modelData)
}
// Didn't provide this so I made up something
struct ModelData {
var games: [Int] = []
}
struct TestData {
static let games: [Int] = [1,2,9]
}
extension Container {
var modelData: Factory<ModelData> {
self { ModelData() }
.scope(.session)
.onPreview { ModelData(games: TestData.games) }
.onTest { ModelData(games: TestData.games) }
}
} And see "Debug: 3" in the Preview. If I comment out the onPreview I see 0, as expected/ |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have defined a scope and applied it to a factory. I have also defined an
onPreview
andonTest
context for the factory.In one of my preview structs, I have the following:
Unfortunately, the test data is never available in the preview.
It is not clear to me what I am doing wrong. Any pointers would be greatly appreciated. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions