struct User: CKModel {
var record: CKRecord!
@CKField("name")
var name: String
init() { }
}
struct Todo: CKModel {
var record: CKRecord!
@CKTimestamp(.creation)
var creationDate: Date?
@CKTimestamp(.modification)
var modificationDate: Date?
@CKField("text")
var text: String
@CKField("tags", default: [])
var tags: [String]
@CKField("isCompleted")
var isCompleted: Bool
@CKReferenceField("user")
var user: User?
init() { }
}
try await todo.save(on: <#CKDatabase#>)
try await todo.delete(on: <#CKDatabase#>)
try await Todo.query(on: <#CKDatabase#>).all()
try await Todo.query(on: <#CKDatabase#>).first()
try await Todo.query(on: <#CKDatabase#>).limit(10)
try await Todo.query(on: <#CKDatabase#>).filter(\.$isCompleted == true).all()
try await Todo.query(on: <#CKDatabase#>).sort(\.$modificationDate, order: .descending).all()
try await Todo.query(on: <#CKDatabase#>).field(\.$text, \.$isCompleted, \.$user).all()
try await Todo.query(on: <#CKDatabase#>).with(\.$user).all()
let todos = try await Todo.query(on: <#CKDatabase#>)
.filter(\.$isCompleted == true)
.sort(\.$modificationDate, order: .descending)
.field(\.$text, \.$isCompleted, \.$user)
.with(\.$user)
.all()