Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyncKit.CloudKitSynchronizer.SyncError2, recordNotFound #163

Open
Mr-ZNN opened this issue Aug 30, 2021 · 1 comment
Open

SyncKit.CloudKitSynchronizer.SyncError2, recordNotFound #163

Mr-ZNN opened this issue Aug 30, 2021 · 1 comment

Comments

@Mr-ZNN
Copy link

Mr-ZNN commented Aug 30, 2021

I am trying to share my records, but it keeps reporting an error SyncKit.CloudKitSynchronizer.SyncError2.
I located the problem here.

guard let modelAdapter = modelAdapter(for: object),
            let record = modelAdapter.record(for: object) else {
            completion?(nil, CloudKitSynchronizer.SyncError.recordNotFound)
            return
}
fileprivate func modelAdapter(for object: AnyObject) -> ModelAdapter? {
        for modelAdapter in modelAdapters {
            if modelAdapter.record(for: object) != nil {
                return modelAdapter
            }
        }
        return nil
}

this modelAdapters is nil. Why is this?
Below is my model class:

class BaseModel: Object, PrimaryKey {
    /// id
    @objc dynamic var id: String = UUID().uuidString
    
    /// primaryKey
    /// - Returns: primaryKey
    override class func primaryKey() -> String {
        return "id"
    }
}
class EventParent: BaseModel {
    let parents = LinkingObjects(fromType: Event.self, property: "parent")
    @objc dynamic var isSharing: Bool = false
    @objc dynamic var isShared: Bool = false
}
class Event: BaseModel, ParentKey {
    @objc dynamic var parent: EventParent?
    @objc dynamic var name: String = ""
    static func parentKey() -> String {
        return "parent"
    }
}
@Mr-ZNN
Copy link
Author

Mr-ZNN commented Aug 31, 2021

I seem to have solved the problem.

synchronizer.share(object: eventParent,
                   publicPermission: .readOnly,
                   participants: [],
                   completion: { (share, error) in
    share?[CKShare.SystemFieldKey.title]  = event.name as CKRecordValue
    completionHandler(share, container, error)
})

Before this. The synchronizer is :
lazy var sharedSynchronizer = CloudKitSynchronizer.sharedSynchronizer(containerName: CloudKitToolConfig.containerName, configuration: self.realmConfiguration)
Change to the same as sync is OK:
synchronizer = CloudKitSynchronizer.privateSynchronizer(containerName: CloudKitToolConfig.containerName, configuration: self.realmConfiguration, recordZoneID: CloudKitToolConfig.zoneID)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant