Harmony icon indicating copy to clipboard operation
Harmony copied to clipboard

Multiple model variables that include ID interfere with CloudKit sync.

Open haIIux opened this issue 1 year ago • 3 comments

If the user has a model that has more than one object in which has the word ID or id in it, the func nextRecordZoneChangeBatch on Line 192, the return on Line 206 will return a null record. This means that there will be no CloudKit sync possible and there is no specific error reflecting this.

Unsure if this is relevant to #3.

// Bad Model
struct Achievement: HRecord, Codable, Identifiable, Hashable {
    var id: UUID = UUID()
    var achievementID: String
    
    var zoneID: CKRecordZone.ID {
        return CKRecordZone.ID(
            zoneName: "Achievement",
            ownerName: CKCurrentUserDefaultName
        )
    }
    
    var archivedRecordData: Data?
    
    var record: CKRecord {
        let encoder = CKRecordEncoder(zoneID: zoneID)
        return try! encoder.encode(self)
    }
}

// Acceptable Model
struct Achievement: HRecord, Codable, Identifiable, Hashable {
    var id: UUID = UUID()
    var achievementType: String
    
    var zoneID: CKRecordZone.ID {
        return CKRecordZone.ID(
            zoneName: "Achievement",
            ownerName: CKCurrentUserDefaultName
        )
    }
    
    var archivedRecordData: Data?
    
    var record: CKRecord {
        let encoder = CKRecordEncoder(zoneID: zoneID)
        return try! encoder.encode(self)
    }
}

haIIux avatar Mar 11 '24 21:03 haIIux

I'll see if I can replicate this in the near future. Definitely some more checks could be added.

aaronpearce avatar Apr 02 '24 22:04 aaronpearce

Are there any insights to this? I currently have no access to a paid developer account so I can't test this behaviour but I am wondering whether this is related to the recordID parsing or the CloudKit Codable implementation. I am currently looking at your package as one way for me to add syncing to a future app but I would like more insights on this bug as I think it could easily trip me up in the future.

dehlen avatar Jul 16 '24 06:07 dehlen

@dehlen I haven't dived deep into this bug as of yet to reproduce it and confirm it is an active bug still.

aaronpearce avatar Jul 29 '24 08:07 aaronpearce

Based on my testing, this does not occur within my own project where I have variables named with iD within them. It shouldn't conflict in theory.

Closing for now.

aaronpearce avatar Oct 20 '24 19:10 aaronpearce