I am making a code that displays all the messages in a table view. To & From. The problem I am running into is the arrays are different lengths and when comparing them the loop stops at the shortest on instead of continuing.
What Im doing is taking the two different arrays & Sort them into 1 larger array thats a combination but sort them based on the time in comparison to the other.
I'm using Swift & I'm also using Parse to query the information.
I'll admit I'm not the best with arrays. Would this be a good time for a dictionary of sent messages & Recieved messages and then loop through?
for var i = 0; i <= self.messagesPFObjectResults.count; i++ {
let sentMessagesInfo = sentMessagesObject![i] //This Equals 7
let recievedMessageInfo = recievedMessagesObject![i] // this equals 8
if sentMessagesInfo.createdAt?.timeIntervalSinceReferenceDate >= recievedMessageInfo.createdAt?.timeIntervalSinceReferenceDate {
self.messagesPFObjectResults.append(recievedMessageInfo)
print("message recieved at: \(recievedMessageInfo.createdAt!)")
print(false)
} else if sentMessagesInfo.createdAt?.timeIntervalSinceReferenceDate <= recievedMessageInfo.createdAt?.timeIntervalSinceReferenceDate {
self.messagesPFObjectResults.append(sentMessagesInfo)
print("message sent at: \(sentMessagesInfo.createdAt!)")
print(true)
}
print(i)
}