Post

Replies

Boosts

Views

Activity

Failed to find a currently activated model container
Hi, i'm trying out SwiftData in Xcode 15.0 beta 5. I’m building a POC of a Note app using SwiftData for the data persistence. I started by creating a new model SimpleNote, where i could successfully implement a CRUD of a note. Now i want to add a new feature introducing the TODO list, however when i tried add the new relationship between the new model TodoItem to SimpleNote the app crashes with the following error: NotesPOC crashed due to fatalError in ModelContainer.swift at line 167. failed to find a currently active container for SimpleNote Both models works fine independently, only crashes when the Relationship is set. I tried to clean simulator data, remove DerivedData, clean the Build Folder but nothing works. The code: SimpleNote.swift: final class SimpleNote: Identifiable { let uuid = UUID() var title: String = "" var content: String = "" var createdAt: Date = Date() var modifiedAt: Date = Date() var theme: String = "" @Relationship(.cascade) var todoList: [TodoItem] = [] init(title: String, content: String, createdAt: Date, modifiedAt: Date, todoList: [TodoItem]) { self.title = title self.content = content self.createdAt = createdAt self.modifiedAt = modifiedAt self.theme = Theme.random().rawValue self.todoList = todoList } } TodoItem.swift: import Foundation import SwiftData @Model class TodoItem: Identifiable { let uuid = UUID() var isCompleted: Bool = false var content: String = "" init(isCompleted: Bool, content: String) { self.isCompleted = isCompleted self.content = content } } NoteApp.swift: import SwiftData @main struct StickyNotesPOCApp: App { var body: some Scene { WindowGroup { NavigationStack { ContentView() .frame(maxWidth: .infinity, maxHeight: .infinity) .background(.black) } } .modelContainer(for: [SimpleNote.self, TodoItem.self]) } } Has anyone faced this issue? am i missing something?
1
2
1.4k
Aug ’23