I've been trying to use the example from this session to tweak the default SwiftData template, allowing for syncing of the data across devices. When I added the following code, I get the above error:
@main
struct ItemApp: App {
let items = ModelConfiguration(schema: Schema([Item.self]), url: URL(filePath: "/path/to/item.store"), cloudKitContainerIdentifier: "iCloud.com.app.Item")
let container = try ModelContainer(for: items). // ERROR HERE
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(container)
}
}
Cannot use instance member 'items' within property initializer; property initializers run before 'self' is available
Any pointers would be helpful.
I noticed the same! The code the session uses at 6:58 isn’t working. The
.modelContainer(for: [Trip.self, BucketListItem.self, LivingAccommodation.self])
code you’ve mentioned in the other comment is only for simple cases, and not really something to achieve the customization like yours …