来自复合查询的对象不会使用解析api固定在iOS上

时间:2015-10-15 16:28:12

标签: ios swift parse-platform

我在查询PFQueryTableViewController类的表方法时有一个复合查询:

func baseQuery() -> PFQuery {
    let ownedChannels = PFQuery(className: "Channel").whereKey("owner", equalTo: PFUser.currentUser()!)
    let subscribedPrivateChannels = PFQuery(className: "Channel").whereKey("subscribers", equalTo: PFUser.currentUser()!)

    let query = PFQuery.orQueryWithSubqueries([ownedChannels, subscribedPrivateChannels])
    query.orderByDescending("createdAt")

    return query
}

override func queryForTable() -> PFQuery {
    return baseQuery().fromLocalDatastore()
}

然后我使用刷新功能从服务器获取数据:

func refreshLocalDataStoreFromServer() {
    baseQuery().findObjectsInBackgroundWithBlock { (parseObjects,  error) -> Void in
        if error == nil {
            print("Found \(parseObjects!.count) parseObjects from server")
            // First, unpin all existing objects
            PFObject.unpinAllInBackground(self.objects as? [PFObject], block: { (succeeded, error) -> Void in
                if error == nil {
                    // Pin all the new objects
                    PFObject.pinAllInBackground(parseObjects, block: { (succeeded, error) -> Void in
                        if error == nil {
                            // Once we've updated the local datastore, update the view with local datastore
                            self.shouldUpdateFromServer = false
                            self.loadObjects()
                        } else {
                            print("Failed to pin objects")
                        }
                    })
                }
            })
        } else {
            print("Couldn't get objects")
        }
    }
}

然后刷新我使用的本地商店中的数据:

override func objectsDidLoad(error: NSError?) {
    super.objectsDidLoad(error)
    if self.shouldUpdateFromServer {
        self.refreshLocalDataStoreFromServer()
    } else {
        self.shouldUpdateFromServer = true
    }
}

shouldUpdateFromServer是使用true

初始化的bool值

这适用于常规查询,在这种情况下,它成功固定ownedChannels,但不会固定第二个查询中的频道。

parseObjects方法中记录refreshLocalDataStoreFromServer时,会显示所有查询结果。

subscribers是通道和用户对象之间的解析关系。

0 个答案:

没有答案