一个键上的两个查询约束与解析和Swift [英] Two Query Constraints On One Key with Parse and Swift
问题描述
guys,我试图获取所有的用户名不包括在数组中的PFUsers( dontShowUsers
。我也想限制查询的变量 name
,这将获得用户名等于用户名搜索的所有用户,但是当我这样做:
guys, I am trying to get all the PFUsers whose username is not included in an array (dontShowUsers
. I also want to limit the query with the variable name
, which gets all users whose username is equal a name the user searches. However when I do this:
findUsers.whereKey("username",containsString:name)
findUsers.whereKey("username",notContainedIn:dontShowUsers)
每个用户都显示,它执行这两个查询,并将它们加在一起我想约束第一个 whereKey
Every user shows. It peforms both these queries, and adds them together. I want to constrain the first whereKey
with the second whereKey
. What would be the best way to go about this?
推荐答案
p>这是一种方式
println(geoPoint)
user["location"] = geoPoint
let rejectedUsers: [String] = user["rejected"].copy() as [String]
let acceptedUsers: [String] = user["accepted"].copy() as [String]
let ignoredUsers = rejectedUsers + acceptedUsers
var query = PFUser.query()
query.whereKey("location", nearGeoPoint: geoPoint)
query.whereKey("username", notEqualTo: user.username)
query.whereKey("gender", equalTo: user["interestedIn"])
query.whereKey("username", notContainedIn: ignoredUsers)
query.limit = 10
query.findObjectsInBackgroundWithBlock({
(objects: [AnyObject]!, error2: NSError!) -> Void in
if error2 != nil {
println(error2)
} else {
if objects.isEmpty {
println("empty query")
} else {
for object in objects {
self.usernames.append(object.username)
self.userImages.append(object["image"] as NSData)
注意我是如何从parse
复制我的用户[rejected创建ignoredUsers
notice how i had to copy my user["rejected"] array from parse then i used + to create "ignoredUsers"
然后我可以使用:
query.whereKey(username,notContainedIn :ignoredUsers)
query.whereKey("username", notContainedIn: ignoredUsers)
这篇关于一个键上的两个查询约束与解析和Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!