如何分组PFObject? Parse / Swift

时间:2016-08-14 11:19:47

标签: ios iphone swift parse-platform

您好我正在尝试对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)
        }
    }
}

1 个答案:

答案 0 :(得分:0)

没有内置功能,你必须自己做,例如当你想要决定该消息的图像是否应该是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
   }
}