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.
感谢Nick DiZazzo ...将代码的最后一行更改为:
let daysAlive = (dateToday - birthDate).in(.day, fromDate: dateToday)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.