I am working with sharing data through CloudKit and Core Data. I share NSManagedObject
s, using:
persistentContainer.share([object], to: nil) { sharedIDs, s, container, error in
if let error = error {
fatalError(error.localizedDescription)
}
if let share = s {
completion(share)
}
}
and that works. However, when I would like to receive the CKShare's object, using:
let operation = CKFetchShareMetadataOperation(shareURLs: [shareURL])
operation.shouldFetchRootRecord = true
var cache = [CKShare.Metadata]()
operation.perShareMetadataResultBlock = { url, result in
switch result {
case .failure(let error):
print("\(#function) Error during downloading the metadata for \(url.absoluteString): ", error.localizedDescription)
case .success(let metadata):
cache.append(metadata)
}
}
operation.fetchShareMetadataResultBlock = { result in
switch result {
case .failure(let error):
completion(.failure(error))
case .success(_):
completion(.success(cache))
}
}
operation.qualityOfService = .userInitiated
CKContainer.default().add(operation)
The metadata's rootRecord is always nil. In the Apple's documentation we can read:
For a shared record hierarchy, the hierarchicalRootRecordID property contains the ID of the share’s root record. When using CKFetchShareMetadataOperation to fetch metadata, you can include the entire root record by setting the operation’s shouldFetchRootRecord property to true (...). This functionality isn’t applicable for a shared record zone because, unlike a shared record hierarchy, it doesn’t have a nominated root record (https://developer.apple.com/documentation/cloudkit/ckshare/metadata).
Is there a different way to get the shared object from CKShare?