ios - Get elements from array where date is today -
i have array of objects property date of type nsdate. array includes future days , past days.
i want array of elements array includes dates in today, not last 24 hours.
i ordered elements descending (new old):
alldashboards.sortinplace({ $0.date!.compare($1.date!) == nscomparisonresult.ordereddescending
i tried loop, check if date yesterday , cut array there, doesn't work may no element yesterdays date:
dash in alldashboards { if (nscalendar.currentcalendar().isdateinyesterday(dash.date!)) { print(i) alldashboards.removerange(range.init(start: 0, end: i)) break } += 1 }
is there method see if date past day instead of if date part of day?
one-liner:
let todaydashboards = alldashboards.filter { nscalendar.currentcalendar().isdateintoday($0.date!) }
Comments
Post a Comment