PFQuery 中的 IncludeKeys 不返回所有关系数据

IncludeKeys in PFQuery not returning all relational data

我正在使用 PFQueryTableViewController 从 Parse 检索对象。这个特定的 Parse class 具有三列(组、类别、客户端),它们是指向其他 Parse classes 的指针。我想使用 includeKey 选项为每个指针对象引入所有对象数据。但是,当我 运行 下面的代码时,我确实检索了关于每个指针列(如 ObjectID)的基本数据,但是 none 的附加列,如类别的 "name" 列class.

override func queryForTable() -> PFQuery {
        let query:PFQuery = PFQuery(className:self.parseClassName!)
        query.whereKey("client", equalTo: currentUser!)
        query.whereKey("status", equalTo: "Open")
        query.whereKey("expires", greaterThan: NSDate())
        query.includeKey("group")
        query.includeKey("category")
        query.includeKey("client")
        query.orderByAscending("expires")

        if(objects?.count == 0)
        {
            query.cachePolicy = PFCachePolicy.CacheThenNetwork
        }

        return query
    }

当我的 PFQueryTableViewController 调用它的 cellForRowAtIndexPath 函数时,我有代码来获取通过 includeKey

引入的类别对象的 'name' 列
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
    ...
    if let category = task["category"] as? PFObject {
        cell?.categoryLabel.text = String(category["name"])
    }
    ...
}

运行 检索类别的 'name' 值导致以下错误并在 Xcode 中崩溃:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Key "name" has no data.  Call fetchIfNeeded before getting its value.'

当我尝试访问我的指针引用对象的任何其他列时,也会出现同样的错误。

当我 print(category) 我似乎在我的日志中得到一个有效的(但空的)对象,没有额外的列,比如 'name':

<Category: 0x13c6ed870, objectId: mEpn6TH6Tc, localId: (null)> {
}

我已经成功地测试了调用建议的提取查询来检索每个指针列丢失的指针数据,但是(恕我直言)额外的提取破坏了 includeKey 查询选项限制 API 请求。

我的一个想法是 PFQuery 可能只允许一个 includeKey 调用。但是,我通过 Parse's own iOS documentation 和各种开发人员 post 所做的研究并未表明查询可以具有的最大 includeKeys 数量有任何限制。

我是在做一些不受 Parse 支持的事情,还是我只是在语法上没有以正确的方式检索每个指针的对象数据?

我运行使用 posting (1.1.6) 和 Parse (1.9.0) Xcode 7.0.1[=23] 的最新 ParseUI =]

提前感谢您阅读我的post!我才学习 iOS 开发几个月,所以这既有趣又令人沮丧!

cell.category.text = object.objectForKey("category")!.objectForKey("name") as! String

另外,使用另一个 "version" 的 cellForRowAtIndexPath,一个用于 PFQueryTableViewControllers:

  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject!) -> PFTableViewCell? {
    //4

    let cell = tableView.dequeueReusableCellWithIdentifier("yourCellIdentifier", forIndexPath: indexPath) as! yourCell


        return cell


}

这允许您使用我回答的上述语法。