swift - '无法对类型 : PFRelation' Swift 进行比较查询

标签 swift parse-platform pfrelation

我正在尝试查询我的应用程序中用户尚未添加为“ friend ”的所有现有用户。我收到错误

Cannot do a comparison query for type: PFRelation

这是我当前的代码:

 override func queryForTable() -> PFQuery {

    let currentFriends : PFRelation = PFUser.currentUser()!.relationForKey("friends")

    // Start the query object
    let query = PFQuery(className: "_User")
    query.whereKey("username", notEqualTo: currentFriends)

    // Add a where clause if there is a search criteria
    if UserInput.text != "" {
        query.whereKey("username", containsString: UserInput.text)
    }

    // Order the results
    query.orderByAscending("username")

    // Return the qwuery object
    return query
}

我该如何解决这个问题?谢谢

最佳答案

我以某种方式解决了我的问题....我无法比较 PFRelation,所以我创建了一个辅助 Parse 类,它将添加其他用户的用户保存为“来自”,将他们添加的用户保存为“至”,然后我可以像这样比较它们。

let currentUser = PFUser.currentUser()?.username

    let currentFriends = PFQuery(className: "Friends")
    currentFriends.whereKey("from", equalTo: currentUser!)

    // Start the query object
    let query = PFQuery(className: "_User")
    query.whereKey("username", doesNotMatchKey: "to", inQuery: currentFriends)

我希望这对以后的人有帮助。

关于swift - '无法对类型 : PFRelation' Swift 进行比较查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33601588/

相关文章:

ios - 使用 SKCameraNode 放大时 SKLabelNode 模糊

ios - 停止 Segue 并传递到下一个查看警报中显示的文本字段的内容 - Swift

ios - 快速地,我如何缩放和定位 SKSpriteNode 以适合每部 iPhone?

java - 如何解析指针数组中的 "include"成员?

swift - 从 Parse 检索到所有响应后执行操作

iOS - 用于添加 friend 的 Parse.com PFRelation 仅添加当前用户的关系,而不是添加 friend 的关系

ios - 如何在 tableview 中显示姓名,就像在 iphone 联系人列表中一样,包含 A 到 Z 部分

ios - TableCell中的PFQuery导致图像跳转

ios - 无法从 Parse iOS Swift 查询用户名

ios - PFRelation 对象或查询键?