我正在尝试查询我的应用程序中用户尚未添加为“ 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/