0
這是我的代碼:分析查詢.whereKey
func loadData() {
data.removeAllObjects()
isLiking.removeAll(keepCapacity: true)
likes.removeAll(keepCapacity: true)
var followedUserQuery:PFQuery = PFQuery(className: "Followers")
followedUserQuery.whereKey("follower", equalTo: PFUser.currentUser()!.objectId!)
followedUserQuery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if let objects = objects {
for object in objects {
var followedUser = object["user"] as! String
println(followedUser)
var postQuery:PFQuery = PFQuery(className: "Posts")
var postQuery:PFQuery = PFQuery(className: "Posts")
postQuery.whereKey("postedBy", equalTo: followedUser || PFUser.currentUser()!.objectId!) // cannot invoke 'whereKey' with an argument list of type '(String, equalTo: Bool)'
postQuery.orderByDescending("createdAt")
postQuery.findObjectsInBackgroundWithBlock ({ (objects, error) -> Void in
if let objects = objects {
for object in objects {
if let post = object as? PFObject {
self.data.addObject(object)
我得到上面的代碼中的註釋錯誤。我想檢索類Posts
中的posts
,該類將由後面的用戶發佈並由當前用戶發佈。我怎樣才能做到這一點?通過使用此我只是得到當前用戶的帖子
var postQuery:PFQuery = PFQuery(className: "Posts")
postQuery.whereKey("postedBy", equalTo: followedUser)
postQuery.whereKey("postedBy", equalTo: PFUser.currentUser()!.objectId!)
:我想這一點。
但這個工作。 是否有任何其他方式來獲取由後續用戶和當前用戶發佈的帖子?我願意接受任何類型的建議。
你能告訴我的代碼,我嘗試這樣做: 'VAR followedUser = [對象 「用戶」 作爲字符串 VAR currentUser! = PFUser.currentUser()?OBJECTID self.postedByUsers.append(followedUser) self.postedByUsers.append(currentUser!) 的println(self.postedByUsers) VAR postQuery:PFQuery = PFQuery(類名: 「文章」 ) postQuery.whereKey(「postedBy」,containedIn:self.postedByUsers) 'it dint work。 –
If by not not work y你的意思是它沒有返回任何結果,那麼我不確定你要求我做什麼。如果它不能編譯,那麼這是一個單獨的問題。它看起來像你記錄你創建的數組。轉到parse.com,轉到您的Posts表格,查看postingBy列,看看是否有任何帖子符合您剛創建的條件,即「找到我的帖子,其中的帖子字符串等於這個或這個」 –
我使用println後添加它給出這個陣列:[P2XutaEa6f,SiA72FwNi2] [P2XutaEa6f,SiA72FwNi2,xpkeERfmbz,SiA72FwNi2],實際上這是因爲我追加它在for循環我猜。所以它追加第一個用戶跟隨當前用戶和currentUserId,然後在第二個循環中的其他用戶和當前userId ..我該如何解決這個問題? –