Skip to content

Instantly share code, notes, and snippets.

@StewartLynch
Last active October 2, 2024 18:26
Show Gist options
  • Save StewartLynch/4a3fbad288ce6352678fffc3579de073 to your computer and use it in GitHub Desktop.
Save StewartLynch/4a3fbad288ce6352678fffc3579de073 to your computer and use it in GitHub Desktop.
import SwiftData
import SwiftUI
struct MockData: PreviewModifier {
func body(content: Content, context: ModelContainer) -> some View {
content
.modelContainer(context)
}
static func makeSharedContext() async throws -> ModelContainer {
let container = try! ModelContainer(
for: <#Model#>.self,
configurations: ModelConfiguration(isStoredInMemoryOnly: true)
)
// Insert objects here
return container
}
}
extension PreviewTrait where T == Preview.ViewTraits {
static var mockData: Self = .modifier(MockData())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment