Why the cloudKitRecordType not a class property?
I think in the CloudKitRecordRepresentable protocol, the cloudKitRecordType should be a static var property.
here is the code sample.
func fetchRecords(type: CKRecord.RecordType) async throws -> ([CKRecord], CKQueryOperation.Cursor?)
If I want to fetch a record list, I need pass the recordType to the function, but I can't get the RecordType from the CustomCloudKitCodable class, I have to initialize a instance ,then pass the instance.cloudKitRecordType to the function.
Why don't let the cloudKitRecordType to be a static var property?
That's a great suggestion indeed.
In fact, in a recent project of mine, I ended up shadowing the CustomCloudKitCodable protocol with my own custom protocol in order to get this functionality.
I'll see about making that available for all CloudKitRecordRepresentable types.
In the meantime, if you'd like to replicate what I've done here so that you can have this in your own project, here's how that can be done, taken directly from my project:
public protocol CSCloudKitRecord: CustomCloudKitCodable {
static var cloudKitRecordType: String { get }
}
public extension CSCloudKitRecord {
static var cloudKitRecordType: String { String(describing: Self.self) }
var cloudKitRecordType: String { Self.cloudKitRecordType }
}
As you can see, I've made a CSCloudKitRecord protocol which inherits from CustomCloudKitCodable and includes the requirement for a static var cloudKitRecordType. I've also added an extension to my custom protocol so that by default the record type matches the Swift type name, and so that the non-static cloudKitRecordType requirement can be satisfied automatically.
Hope this helps, thanks for the suggestion!