: 라인오류 : 이진 연산자 '<='는 'Int'유형의 피연산자에 적용 할 수 없습니다. 및 '내부'
Binary operator '<=' cannot be applied to operands of type 'Int?' and 'Int'
: if differenceOfDate.second <= 0
사람이 도움을 주시기 바랍니다 수 있습니다!
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."
}
문서 https://developer.apple을 조회하세요 .com/documentation/foundation/calendar/2292887-datecomponents를 사용하면'NSDate'가 아닌'Date' 유형의 매개 변수를 사용하게됩니다. –
관련 : https://stackoverflow.com/questions/41198803/how-to-convert-from-nsdatetimeintervals since1970-to-nsdate. –
"Date"를 사용하는 것보다 "이진 연산자 '<='를 'Int'유형의 피연산자에 적용 할 수 없습니다. and Int 'if line if differenceOfDate.second <= 0' – Danjhi