我收到一个错误:“参数’coder’在调用中缺少参数,用于以下代码:
var components = NSDateComponents() components.setValue(1,forComponent: NSCalendarUnit.CalendarUnitMonth); var expirationDate = NSCalendar.currentCalendar().dateByAddingComponents(components,toDate: NSDate(),options:0)
文档要求:
NSCalendar.currentCalendar().dateByAddingComponents(<#comps: NSDateComponents?#>,toDate: <#NSDate?#>,options: <#NSCalendarOptions#>)
任何人都可以看到我失踪了吗?我没有看到一个名为’coder’的参数。
在Swift 1.2中语法上是正确的:
原文链接:https://www.f2er.com/swift/320684.htmlvar components = NSDateComponents() components.setValue(1,forComponent: NSCalendarUnit.CalendarUnitMonth); let date: NSDate = NSDate() var expirationDate = NSCalendar.currentCalendar().dateByAddingComponents(components,toDate: date,options: NSCalendarOptions(0))
在Swift 2.0中,您需要更新此代码有点像这样:
let components: NSDateComponents = NSDateComponents() components.setValue(1,forComponent: NSCalendarUnit.Month); let date: NSDate = NSDate() let expirationDate = NSCalendar.currentCalendar().dateByAddingComponents(components,options: NSCalendarOptions(rawValue: 0))