Many thanx Karin, this exactly solved my issue with the "failed to find a currently active container" error I was getting on Previews that required some model data as input!
@nwalter08 Жыл бұрын
I have been stuck on this for weeks, thank you so much!!
@SwiftyPlace Жыл бұрын
Happy to help!
@luisgomezreus732 Жыл бұрын
Thank you very much for the video. I'm starting a new project with swiftdata and I wasn't sure how the previews worked until I saw your video. Thank you very much again.
@RafaelGuima Жыл бұрын
Works Fine - one change simple: in previewContainer ... let container = try ModelContainer(for: Todo.self, configurations: ModelConfiguration(isStoredInMemoryOnly: true)) Thanks 😍
@allenwixted199211 ай бұрын
Thanks man!
@ErwinFoekema11 ай бұрын
This solved my struggles with SwiftData & Previews, tnx
@sanjeev37997 ай бұрын
Thank you Karin!
@sergiovinhal59345 ай бұрын
Thank you so Much !
@luisgomezreus732 Жыл бұрын
An idea to select the persistModel is to pass a key and a value to filter the query. struct ModelPreview2: View { var key: KeyPath var value: String var content: (Model) -> Content init(key: KeyPath, value: String, @ViewBuilder content: @escaping (Model) -> Content) { self.key = key self.value = value self.content = content } var body: some View { PreviewContentView(key: key, value: value, content: content) .modelContainer(previewContainer) } private struct PreviewContentView: View { @Query private var models: [Model] var key: KeyPath var value: String var content: (Model) -> Content var body: some View { if let model = filtered.first { content(model) } else { ContentUnavailableView("Couldn't load model for preview", systemImage: "xmark") } } private var filtered: [Model] { models.filter { $0.getValue(forKey: key) == value } } } } and use like this #Preview() { ModelPreview2(key: \Person.legalId, value: "12345678N") { model in PersonView(person: model) .modelContainer(previewContainer) } }
@artemis99999 Жыл бұрын
Great thanks!
@vitaliizadubnyi102111 ай бұрын
Thank a lot
@magpro8775 Жыл бұрын
Amazing 🥰
@SwiftyPlace Жыл бұрын
Thanks 🤗
@piteke1009 ай бұрын
Hi, I’m continuing to study SwiftData by repeating all the tutorials but I can’t understand one thing: I have to create an app with a default list (which therefore no data needs to be added) and this list is contained in a toggle. How do I make only the toggle state persistent?
@gmjelle Жыл бұрын
Nice how fast you're aboard the SwiftData train. As a new swift dev, swiftdata seems like a very good way forward. Do you know why Swiftdata models can not conform to "Codable"?
@ErwinFoekema10 ай бұрын
The previews work fine. But when I want to upload to xcode cloud I get Cannot find 'ModelPreview' in scope or Cannot find 'previewContainer' in scope How to solve this?
@noahzsol Жыл бұрын
Awesome - this works, but when I modify a view the preview now crashes, and I need to delete all stale app data using Terminal to get it working again. Do you have any ideas as to what I need to fix?
@noahzsol Жыл бұрын
Worked it out! After making the container in previewContainer, I needed to add a ModelConfiguration with isStoredInMemoryOnly: true, and now it works perfectly!
@kevinkivo Жыл бұрын
Anyone know how to activate the undo manager for a model context if you are passing a previewContainer (or any other custom container) to the .modelContainer modifier? The syntax for isUndoEnabled: true only works if you pass 'for: [ModelA.self, ModelB.self, etc.], isUndoEnabled: true' into the .modelContainer modifier. But doing that defeats the purpose of the custom container.
@gordongudmundson4982 Жыл бұрын
How would you do the same thing with a view that needs a bindable object like an edit view?
@gordongudmundson4982 Жыл бұрын
I figured this out by changing from @Binding to @Bindable in the view thanks to another video of yours! Thanks!
@zardashtjaza1343 Жыл бұрын
hello Karin please answer my email I just send it from your website