简体   繁体   English

解析:不查询本地数据存储中的已保存对象

[英]Parse: Does not query saved objects in local datastore

I am currently developing a inventory app. 我目前正在开发库存应用。 My goal is to retrieve objects from Parse and then saving onto the local datastore. 我的目标是从Parse中检索对象,然后保存到本地数据存储中。 Querying objects from Parse and saving them works (because of the console message) but querying later on from the local datastore, does not retrieve anything! 从Parse中查询对象并保存它们是可行的(由于控制台消息),但是稍后从本地数据存储区中进行查询不会检索任何内容! Here's my code: 这是我的代码:

let query = PFQuery(className: "Publication")
    query.limit = 150
    query.selectKeys(["publication_id","publication_Type","publication_Name"])
    dispatch_async(dispatch_get_main_queue()) { () -> Void in
        query.findObjectsInBackgroundWithBlock({ (pubObject, error) -> Void in
            if error == nil {
                print("Succesfully retrieved \(pubObject!.count)")

                PFObject.saveAllInBackground(pubObject, block: { (success, error) -> Void in
                    print("Saved \(pubObject!.count) in local DataStore")
                })

            }
        })
    }

This message comes out from the XCode console: 此消息从XCode控制台发出:

"Succesfully retrieved 103 Saved 103 in local DataStore" “成功检索到103在本地DataStore中保存了103”

So far so good right? 到目前为止一切都好吧? This is my code when I am about to query from the local datastore: 这是我要从本地数据存储区查询时的代码:

dispatch_async(dispatch_get_main_queue()) { () -> Void in
        let bookQuery = PFQuery(className: "Publication")
            .fromLocalDatastore()
        bookQuery.whereKey("publication_Type", equalTo: "Book")
        bookQuery.findObjectsInBackgroundWithBlock { (bookObject, error) -> Void in

            if error == nil{
                print("Books found: \(bookObject!.count)")
                self.displayData(bookObject!)

            }
        }
    }

And I get from the console: Books found: 0. 我从控制台得到:找到的书:0。

What gives? 是什么赋予了? What am I doing wrong? 我究竟做错了什么? I read and read and read. 我读,读,读。 NOTHING. 没有。 I thought the ".ignoreACL()" would work but it didn't. 我以为“ .ignoreACL()”可以工作,但是没有。 Can anyone help me please? 谁能帮我吗?

I don't see where you are pinning the PFObject s into the local datastore. 我看不到将PFObject固定到本地数据存储中的位置。 Perhaps that is your problem. 也许那是你的问题。

Calling any of PFObject s save methods saves them back to your parse server, not a local datastore. 调用任何PFObject的save方法会将它们保存回解析服务器,而不是本地数据存储。 Look up how to use pin to accomplish what you want. 查找如何使用pin来完成所需的操作。

Also, dispatching these asynchronous calls to the main queue makes no sense. 同样,将这些异步调用分派到主队列也没有任何意义。 They are already executing on a background queue. 它们已经在后台队列上执行。 In most cases, you only need to dispatch back to the main queue if you want to do something to the UI and that should be done in the completion handler. 在大多数情况下,如果您要对UI进行操作,则只需要分派回主队列即可,这应该在完成处理程序中完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM