getting rid of a warning from SwiftDate for a reference date

61 views Asked by At

I'm getting a warning from SwiftDate "[SwiftDate] Using .in() to extract calendar specific components without a reference date may return wrong values." How can I get rid of this warning?

My code:

let calendar = Calendar.current
let birthDate = calendar.date(from: calendar.dateComponents([.year, .month, .day], from: myBirthday))!
let dateToday = calendar.date(from: calendar.dateComponents([.year, .month, .day], from: Date()))!
let daysAlive = (dateToday - birthDate).in(.day)        

That is the point where the warning occurs.

1

There are 1 answers

0
arakweker On

Thanks to Nick DiZazzo... change the last line of the code to:

let daysAlive = (dateToday - birthDate).in(.day, fromDate: dateToday)