0

我必须在这里写什么?

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 正常工作

谢谢你的帮助,丹尼尔

编辑:我从数据库中读取数据的方式:

var customers : [Entity] {
        let search = Search<Entity>(graph: db).for(types: "Customers")
        return search.sync(completion: nil).sorted { ($0["name"] as! String) < ($1["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 配置 在此处输入图像描述

4

1 回答 1

0

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

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

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

于 2017-04-03T21:52:39.410 回答