I have some data in firebase that I am trying to organize by timestamp. I have incorporated this code into cellForRowAt
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let seconds = post["pub_time"] as? Double {
let timeStampDate = NSDate(timeIntervalSince1970: seconds/1000)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM/dd/yyyy"
let formating = timeStampDate as Date
let timeAgo = timeAgoSinceDate(formating)
cell.Time.text = timeAgo
posts.sort(by: { $0.timeStampDate.compare($1.timeStampDate) == .orderedAscending })
}
But on the posts.sort(by: { $0.timeStampDate.compare($1.timeStampDate) == .orderedAscending })
I keep getting the error expression type bool is ambiguous without more context and I am not sure what I am doing wrong
This is more or less what my view controller looks like
var posts = NSMutableArray()
func loadData(){
Database.database().reference().child("main").child("posts").queryOrdered(byChild: "pub_time").observeSingleEvent(of: .value, with: { snapshot in
if let postsDictionary = snapshot .value as? [String: AnyObject] {
for post in postsDictionary {
posts.add(post.value)
}
self.TableView.reloadData()
}
})
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Configure the cell...
let cell = tableView.dequeueReusableCell(withIdentifier: "Cells", for: indexPath) as! FeedTableViewCell
//Configure the cell
let post = posts[indexPath.row] as! [String: AnyObject]
cell.Title.text = post["title"] as? String
if let seconds = post["pub_time"] as? Double {
let timeStampDate = NSDate(timeIntervalSince1970: seconds/1000)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM/dd/yyyy"
let formating = timeStampDate as Date
let timeAgo = timeAgoSinceDate(formating)
cell.Time.text = timeAgo
}
return cell
}