Custom sorting of array for date in swift
Custom sorting of array for date in swift
I need to sort my array which has object with date property. My array has dates of present and past both. I have to arrange the dates as soonest first. So first all the future dates should appear with soonest first and then dates of past should appear as those who has past should come first. I have implemented following logic but it provides me dates in only one particular order:
arrSortedList = arrSortedList.sorted(by: TimeHelper.getDateFromString(dateInString: $0.warrantyDate!, format: .yyyyMMdd) ?? .distantPast > TimeHelper.getDateFromString(dateInString: $1.warrantyDate!, format: .yyyyMMdd) ?? .distantPast )
Regards
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Your description is a little confusing. Today is August 23. Let's say the array has the values of August 20, 21, 22, 23, 24, 25, and 26. What order do you want? I think you want 24, 25, 26, 23, 22, 21, 20. Please update your question with a clear example of the desired order.
– rmaddy
Aug 23 at 18:21