Hello folks, absolute newbie here.
I'm following a tutorial that I'm trying to adjust to my own needs. In the tutorial the app is sat up in a way that you can add a new entry to a note taking app by tapping on a button which brings in an edit view.
What I'm trying to do is to bring in the edit view by adding it as a tab on the bottom instead.
Here's my ContentView:
import SwiftData
import SwiftUI
struct ContentView: View {
let example = Entry(content: "Example Entry")
var body: some View {
TabView {
LifeEventsView()
.tabItem {
Label("Life events", systemImage: "house")
}
EditEntryView(entry: example)
.tabItem {
Label("Add new event", systemImage: "plus")
}
MattersView()
.tabItem {
Label("What matters", systemImage: "house")
}
}
}
}
#Preview {
ContentView()
}
And here's the EditEntryView:
import SwiftData
struct EditEntryView: View {
@Bindable var entry: Entry
var body: some View {
Form {
TextField("Entry", text: $entry.content, axis: .vertical)
}
.navigationTitle("Edit entry")
.navigationBarTitleDisplayMode(.inline)
}
}
#Preview {
do {
let config = ModelConfiguration(isStoredInMemoryOnly: true)
let container = try ModelContainer(for: Entry.self, configurations: config)
let example = Entry(content: "Example Entry")
return EditEntryView(entry: example)
.modelContainer(container)
} catch {
fatalError("Failed to create model container.")
}
}
The build succeeds but I get an error while running saying: Thread 1: Fatal error: failed to find a currently active container for Entry
I'm sure this is an easy fix but I've been thinking with it for a while with no luck.