Calendar Changed in Swift 3?

做~自己de王妃 提交于 2019-12-24 09:01:00

问题


Hey so I'm working on this little app and I

let durationDateComponents = Calendar(identifier: Calendar.Identifier.gregorian).dateComponents([.year, .month, .day, .hour, .minute, .second], from: Date(), to: christmasDay, options: [])

What do I do here? I get that the error is pointing me to change something with the array, but what?

Thanks!


回答1:


Remove options. That's not part of dateComponents and thus the compiler is having trouble identifying the method.

let calendar = Calendar.current   // or, if you really need gregorian calendar regardless of the current calendar, `Calendar(identifier: .gregorian)`
let components = calendar.dateComponents([.year, .month, .day, .hour, .minute, .second], from: Date(), to: christmasDay)

If you remove options, the method is successfully identified and therefore it is able to correctly interpret the expression.



来源:https://stackoverflow.com/questions/40144465/calendar-changed-in-swift-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!