0

I use this method to compare two dates in one day is,but it look so long. is there another way to compare the two dates if is the same day??

if Calendar.current.component(.day, from: (me.last?.day)!) ==  Calendar.current.component(.day, from: Date())
jnpdx
  • 35,475
  • 5
  • 43
  • 61
fatdrogen
  • 85
  • 1
  • 5
  • 1
    See https://stackoverflow.com/q/37426662/1187415 or https://stackoverflow.com/q/24577087/1187415 or https://stackoverflow.com/q/33813585/1187415. – Martin R Oct 30 '21 at 19:25
  • Are you complaining that your code takes too long at runtime? Is `isDate(_:inSameDayAsDate:)` is also too slow? – rob mayoff Oct 30 '21 at 19:35
  • @robmayoff OP said it is too long not taking too long. Note also that in this case OP can simply use calendar method [isDateInToday](https://developer.apple.com/documentation/foundation/calendar/2293243-isdateintoday) – Leo Dabus Oct 30 '21 at 21:01
  • https://stackoverflow.com/a/43664156/2303865 – Leo Dabus Oct 30 '21 at 21:06

0 Answers0