I need to sort my post array, so that it will be arranged by its date. I think a solution is by looping trough the array and reorder it by creating new array that contain the post. So here is my code:
let newPostArray : NSMutableArray = NSMutableArray()
for post in postArray{
print("sini3")
let postDict = post as? NSDictionary
if postDict!["timeAgo"]?.rangeOfString("d") != nil{
newPostArray.addObject(post)
//here is the problem
}else if postDict!["timeAgo"]?.rangeOfString("w") != nil{
newPostArray.addObject(post)
}else if postDict!["timeAgo"]?.rangeOfString("m") != nil{
newPostArray.addObject(post)
}else{
newPostArray.addObject(post)
}
print("jeng jeng \(newPostArray)")
}
My logic is, after newPostArray.addObject(post)
the loop continue to the next index and observe the second post and so on. How can I do that? Or is there any way I can reorder the array?