Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let dates: [Date] = []
- let hourComponents = DateComponents(hour: 10, minute: 0) //Here provide a better way
- func hourComponentsMatches(date: Date) -> Bool {
- let dateComponents = Calendar.current.dateComponents([.hour, .minute], from: date)
- return hourComponents.hour == dateComponents.hour && hourComponents.minute == dateComponents.minute
- }
- let sortedDates = dates.sorted(by: { first, second in
- switch (hourComponentsMatches(date: first), hourComponentsMatches(date: second)) {
- case (true, true):
- return first < second //If order for all the one with the correct order is wrong, return first > second
- case (false, true):
- return true //if order is wrong, try by returning here false and on the next one true
- case (true, false):
- return false
- default:
- return false
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement