Created
August 3, 2018 06:39
-
-
Save dilipiOSDeveloper/9ddd041b027fe3ec97243a20f89536c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
write this code in method. | |
let message = messages[indexPath.row] | |
if indexPath.row == 0 { | |
return NSAttributedString(string: message.date.dateString(), attributes: [NSAttributedStringKey.font : UIFont.systemFont(ofSize: 13.0, weight: .bold)]) | |
}else { | |
let previousMessage = messages[indexPath.row - 1] | |
if Calendar.current.isDate(previousMessage.date, inSameDayAs: message.date) { | |
return nil | |
}else { | |
return NSAttributedString(string: message.date.dateString(), attributes: [NSAttributedStringKey.font : UIFont.systemFont(ofSize: 13.0, weight: .bold)]) | |
} | |
} | |
And copy this outside of your class | |
public extension Date { | |
public func dateString (format: String = "dd MMM, yyyy") -> String { | |
let formatter = DateFormatter() | |
formatter.dateFormat = format | |
return formatter.string(from: self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment