[英]getting rid of a warning from SwiftDate for a reference date
I'm getting a warning from SwiftDate "[SwiftDate] Using .in() to extract calendar specific components without a reference date may return wrong values." 我从SwiftDate得到警告:“ [[SwiftDate]使用.in()提取没有参考日期的日历特定组件可能会返回错误的值。” 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.