Swiftで「Failed to find any currently loaded container for xxx)」と表示される原因と対処法

swift
Failed to find any currently loaded container for xxx

Schemaに、使用している@Modelクラスが登録されていないことが原因です。

SwiftDataのModelContainerに、使用するすべての@Modelクラスを登録する必要があります。

swift
let schema = Schema([
      Item.self,
      MyData.self
])

関連記事