我正在尝试查询我的应用中用户尚未添加为"朋友"的所有现有用户。我收到了错误
无法对类型进行比较查询: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
}
如何解决此问题?感谢
答案 0 :(得分:5)
我在某种程度上解决了我的问题。我无法比较PFRelation所以我创建了一个帮助Parse类,它保存将其他用户添加为“from”的用户和他们添加为“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)
我希望将来可以帮助某人。