2016-08-14 49 views
1

嗨,我想組PFObjects
例如,考慮一個消息應用程序如何分組PFObjects?解析/斯威夫特

如何根據傳入和傳出消息的用戶名進行分組?

這裏是我有什麼:

var messages = [PFObject]() 

func loadMessages() { 
    let query = PFQuery(className: "Messages") 
    query.whereKey("user", equalTo: PFUser.current()!) 
    query.includeKey("user") 
    query.findObjectsInBackground { (objects, error) in 
     if error == nil { 

      for object in objects! { 
       self.messages.append(object) 
      } 

     } else { 
      print(error!.localizedDescription) 
     } 
    } 
} 

回答

0

沒有內置在它的功能,你必須自己做,比如當你想,以決定是否該消息的圖像應如同接收或傳出...

for object in messages { 
    if object["user_id"] as PFUser == PFUser.currentUser() { 
     //the message is from the same User, set what you need 
     //user_id is a column name in Messages as a pointer to User class class 
    } else { 
     // message was not send from currentUser 
    } 
}