【问题标题】:'Cannot do a comparison query for type: PFRelation' Swift'不能对类型进行比较查询:PFRelation' Swift
【发布时间】:2016-02-09 15:41:47
【问题描述】:

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

无法对类型进行比较查询: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
}

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

【问题讨论】:

    标签: swift parse-platform pfrelation


    【解决方案1】:

    我解决了我的问题....在某种程度上。我无法比较 PFRelation,所以我创建了一个帮助 Parse 类,该类保存将另一个用户添加为“来自”的用户和他们添加为“to”的用户,然后我可以像这样比较它们。

    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)
    

    我希望这对将来的某人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-07
      相关资源
      最近更新 更多