Search code examples
graphicloudcosmicmind

Unable to make Graph + iCloud works


what I have to write here?

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

or

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

I tried everything but I'm unable to make iCloud works

Thank you for your help, Daniel

EDIT: the way I read data form db:

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)}
    }

the way I save the record:

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() }
        }
    }

EDIT 2: the GraphDelegate implementation:

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()
    }


}

EDIT: the iCloud config enter image description here


Solution

  • Thanks to one of my students I found the bug:

    • if you make a record this way everything works fine: let record = Entity(type: "Names", graph: self.db)
    • but if you use this init it doesn't: let record = Entity(type: "Names")

    so the solution is: make a record this way let record = Entity(type: "Names", graph: self.db)