я имел этот код в Swift 2, теперь он имеет ошибку в Swift 3:'init' относится к типу; использование 'типа (из: ...)', чтобы инициализировать новый объект
Ошибка:
'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type
extension Date
{
init(dateString:String) {
let dateStringFormatter = DateFormatter()
dateStringFormatter.dateFormat = "yyyy-MM-dd"
dateStringFormatter.locale = Locale(identifier: "en_US_POSIX")
let d = dateStringFormatter.date(from: dateString)!
// error is here : 'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type
(self as NSDate).init(timeInterval:0, since:d) }
}
Что такое '(self as NSDate)'? Тип 'Date' имеет собственный' init' с теми же параметрами, почему бы не использовать его вместо тщеславия типа? Кроме того, 'init' - это метод уровня класса, а не уровень экземпляра - вот откуда исходит ваша ошибка. – user28434
правый, фиксированный, спасибо! – AVEbrahimi