obtener - string to date swift 4
Creando una fecha futura en swift con NSDate() (4)
La última sintaxis de Swift 3 :
var components = DateComponents()
components.setValue(1, for: .month)
let date: Date = Date()
let expirationDate = Calendar.current.date(byAdding: components, to: date)
Recibo un error: "Falta el argumento para el parámetro ''codificador'' en la llamada" para el siguiente código:
var components = NSDateComponents()
components.setValue(1,forComponent: NSCalendarUnit.CalendarUnitMonth);
var expirationDate = NSCalendar.currentCalendar().dateByAddingComponents(components, toDate: NSDate(),options:0)
Los documentos piden:
NSCalendar.currentCalendar().dateByAddingComponents(<#comps: NSDateComponents?#>, toDate: <#NSDate?#>, options: <#NSCalendarOptions#>)
¿Alguien puede ver lo que me estoy perdiendo? No veo un parámetro llamado ''codificador'' requerido.
Sintaxis para Swift 3
var components = DateComponents()
components.setValue(1, forComponent: .month)
let date: Date = Date()
let expirationDate = Calendar.current.date(byAdding: components, to: date, options: [])
como se ve estar con
swift 4.x
let date = Date()
var components = DateComponents()
components.setValue(1, for: .month)
let expirationDate = Calendar.current.date(byAdding: components, to: date)
swift 2.0
let components: NSDateComponents = NSDateComponents()
components.setValue(1, forComponent: NSCalendarUnit.Month);
let date: NSDate = NSDate()
let expirationDate = NSCalendar.currentCalendar().dateByAddingComponents(components, toDate: date, options: NSCalendarOptions(rawValue: 0))
swift 1.2
var components = NSDateComponents()
components.setValue(1, forComponent: NSCalendarUnit.CalendarUnitMonth);
let date: NSDate = NSDate()
var expirationDate = NSCalendar.currentCalendar().dateByAddingComponents(components, toDate: date, options: NSCalendarOptions(0))
Versión Swift 4
var components = DateComponents()
components.setValue(1, for: .month)
let date: Date = Date()
let expirationDate = Calendar.current.date(byAdding: components, to: date, wrappingComponents: false)
¡Espero que esto ayude!