2

When trying to instantiate a CKRecord from my current datastore, I am unable to initialize it using Seam3. The core data stack and CloudKit are in perfect sync thanks to Seam3. I'm bulding a wishlist application that enables list sharing and I'm trying to implement this feature. Without a CKRecord to send to UICloudSharingController, I can't finish this feature.

I have tried converting to a CKRecord by hand and I don't know what I'm doing wrong.

func loadData() {
        let fetchRequest = NSFetchRequest<List>(entityName: "List")
        let sortDescriptor = NSSortDescriptor(key: "title", ascending: true)
        fetchRequest.sortDescriptors = [sortDescriptor]
        if let result = try? dataController.viewContext.fetch(fetchRequest) {
            lists = result
            tableView.reloadData()
        }
    }
override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        loadData()
        NotificationCenter.default.addObserver(forName: Notification.Name(rawValue: SMStoreNotification.SyncDidFinish), object: nil, queue: nil) { [weak self] notification in
            if notification.userInfo != nil {
                self?.dataController.smStore?.triggerSync(complete: true)
            }
            self?.dataController.viewContext.refreshAllObjects()
            DispatchQueue.main.async {
                self?.loadData()
            }
        }
    }

These are the ways I am populating the tableView. I'm not sure how Seam3 works in the background to populate with the CloudKit Items. But its a seamless bridging between CloudKit and CoreData. Any help would be appreciated.... Thanks!

  • Did you ever figure out how to do this? I ended up doing something like: guard let r`ecord = container.record(for: coreDataObject.objectID) else { return }` `let share = CKShare(rootRecord: toShare)` – goddamnyouryan Mar 26 '21 at 21:28
  • I reverted from using Seam3 as it didn't work for my use case. I went to a custom CloudKit implementation instead. Still couldn't get sharing to work properly. However, now I am looking at the new APIs for NSCloudKitPersistentContainer instead. – Chad Rutherford Mar 30 '21 at 15:08
  • What APIs are you referring to? `record(for:)`? – goddamnyouryan Mar 31 '21 at 18:21
  • Apple introduced new APIs in iOS 13 to enable seamless integration between CoreData and CloudKit. Then in iOS 14, they introduced different containers such as private and shared cloud database. I am researching these to find a better way to enable sharing. – Chad Rutherford Mar 31 '21 at 20:06
  • right sorry I was actually talking about that in my original comment, the container I was referring to an instance of NSCloudKitPersistentContainer (as well as the record(for:) function – goddamnyouryan Apr 01 '21 at 21:20

0 Answers0