Skip to content

Instantly share code, notes, and snippets.

@tunds
Created April 19, 2024 08:00
Show Gist options
  • Save tunds/535a07293766b6fa2d4171ff88625a4d to your computer and use it in GitHub Desktop.
Save tunds/535a07293766b6fa2d4171ff88625a4d to your computer and use it in GitHub Desktop.
import Foundation
import SwiftData
actor ItemsContainer {
@MainActor
static func create(shouldCreateDefaults: inout Bool) -> ModelContainer {
let schema = Schema([Item.self])
let isPaidUser = true // Write your logic here to see if they've paid or not
let configuration = ModelConfiguration(cloudKitDatabase: isPaidUser ? .automatic : .none)
let container = try! ModelContainer(for: schema,
migrationPlan: ToDosMigrationPlan.self,
configurations: [configuration])
return container
}
}
/********/
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(ItemsContainer.create())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment