I am getting a error named:
Binary operator '<=' cannot be applied to operands of type 'Int?' and 'Int'
on line: if differenceOfDate.second <= 0
Can someone please help!
let fromDate = Date(timeIntervalSince1970: TimeInterval(truncating: posts[indexPath.row].postDate))
let toDate = Date()
var calendar = Calendar.current
let components = Set<Calendar.Component>([.second, .minute, .hour, .day, .weekOfMonth, .month])
let differenceOfDate = Calendar.current.dateComponents(components, from: fromDate, to: toDate)
if differenceOfDate.second <= 0 {
cell.DateLbl.text = "now"
}else if differenceOfDate.second > 0 && differenceOfDate.minute == 0 {
cell.DateLbl.text = "\(differenceOfDate.second)s."
}
else if differenceOfDate.minute > 0 && differenceOfDate.hour == 0 {
cell.DateLbl.text = "\(differenceOfDate.minute)m."
}
else if differenceOfDate.hour > 0 && differenceOfDate.day == 0 {
cell.DateLbl.text = "\(differenceOfDate.hour)h."
}
else if differenceOfDate.day > 0 && differenceOfDate.weekOfMonth == 0 {
cell.DateLbl.text = "\(differenceOfDate.day)d."
}
else if differenceOfDate.weekOfMonth > 0 && differenceOfDate.month == 0 {
cell.DateLbl.text = "\(differenceOfDate.weekOfMonth)w."
}
else if differenceOfDate.month > 0 {
cell.DateLbl.text = "\(differenceOfDate.month)m."
}