[英]How to group PFObjects ? Parse / Swift
嗨,我正在嘗試分組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)
}
}
}
沒有內置功能,你必須自己做,例如當你想要決定該消息的圖像應該是Incomming還是Outgoing ...
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
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.