When I try to instantiate a ModelContainer object, I get an error. The error is like this:
Thread 1: Fatal error: Composite Coder only supports Keyed Container.
SingleFolder
is a custom model.
This is my code:
class DatabaseService {
static var shared = DatabaseService()
var container: ModelContainer?
var context: ModelContext?
init() {
do {
container = try ModelContainer(for: [SingleFolder.self])
if let container {
context = ModelContext(container)
}
} catch {
print(error)
}
}
}
I'm expecting to generate a ModelContainer singleton so I can access it anytime. What's wrong with this?
Xcode version 15.0 beta4 Simulator version: iOS 17.0
This is my model:
@Model class SingleFolder {
let creationTime: Date
var editTime: Date
var folderName: String
var frame: CGRect = CGRect.zero
init(creationTime: Date, editTime: Date, folderName: String) {
self.creationTime = creationTime
self.editTime = editTime
self.folderName = folderName
}
}