I have a message board in which the items are sorted by newest to oldest when retrieved from the database. However, after loading the struct in the time order, I would like for the first item to be the current user's message regardless of if it's the latest one or not. I tried doing it with the function below but it turns out that sorts the usernames in order.
Struct Code
struct MessageBoard: Equatable{
var username: String! = ""
var messageImage: UIImage! = nil
var messageId: String! = ""
var timeSince: String! = ""
init(username: String, messageId: UIImage, messageId: String, timeSince: String) {
self.username = username
self.messageImage = messageImage
self.messageId = messageId
self.timeSince = timeSince
}
static func == (lhs: MessageBoard, rhs: MessageBoard) -> Bool {
return lhs.username == rhs.username
}
}
var messageBoardData = [MessageBoard]()
Sorting Code
self.messageBoardData.sort { (lhs, rhs) in return lhs.username > rhs.username }