无法使 Graph + iCloud 正常工作

Unable to make Graph + iCloud works

我要在这里写什么?

db = Graph(cloud: "iCloud.com.devname.appname", completion: { (done, error) in
            if let errore = error {
                debugPrint("Error iCloud: \(errore.localizedDescription)")
                return
            }
        })

db = Graph(cloud: "fantasyString", completion: { (done, error) in
            if let errore = error {
                debugPrint("Errore iCloud: \(errore.localizedDescription)")
                return
            }
        })

我尝试了所有方法,但我无法让 iCloud 工作

谢谢你的帮助,丹尼尔

编辑: 我从 db:

读取数据的方式
var customers : [Entity] {
        let search = Search<Entity>(graph: db).for(types: "Customers")
        return search.sync(completion: nil).sorted { ([=12=]["name"] as! String) < (["name"] as! String)}
    }

我保存记录的方式:

func newCustomer(name:String, phone:String, mail:String, closure: @escaping ()->()) {

        let cliente = Entity(type: "Customers")
        cliente["name"] = name
        cliente["phone"] = phone
        cliente["mail"] = mail
        db.sync { (done, error) in
            if let errore = error {
                debugPrint("Errore addCustomer: \(errore.localizedDescription)")
                return
            }
            if done { closure() }
        }
    }

编辑 2:GraphDelegate 实现:

extension DataManager: GraphDelegate {

    func graphWillPrepareCloudStorage(graph: Graph, transition: GraphCloudStorageTransition) {
        debugPrint("graphWillPrepareCloudStorage")
        if transition == .initialImportCompleted {
            debugPrint("iCloud initialImportCompleted ok")
            self.clientiCont?.tableView.reloadData()
        }
    }

    func graphDidPrepareCloudStorage(graph: Graph) {
        debugPrint("graphDidPrepareCloudStorage")
        self.clientiCont?.tableView.reloadData()
    }

    func graphWillUpdateFromCloudStorage(graph: Graph) {
        debugPrint("graphWillUpdateFromCloudStorage")
        self.clientiCont?.tableView.reloadData()
    }

    func graphDidUpdateFromCloudStorage(graph: Graph) {
        debugPrint("graphDidUpdateFromCloudStorage")
        // refresh clienti
        self.clientiCont?.tableView.reloadData()

        // refresh lista ordini
        self.gestCliCont?.tableOrder.reloadData()

        // refresh oridine
        self.gestOrdCont?.showOrder()
        self.gestOrdCont?.tableProdotti.reloadData()
    }


}

编辑:iCloud 配置

感谢我的一位学生,我发现了错误:

  • 如果您以这种方式进行记录,则一切正常: let record = Entity(type: "Names", graph: self.db)
  • 但是如果你使用这个 init 它不会:let record = Entity(type: "Names")

所以解决方法是:这样记录 let record = Entity(type: "Names", graph: self.db)