我在Swift 2中有这个代码,现在它在Swift 3中有错误:
错误是:
'init'是该类型的成员;使用'type(of:...)'来初始化a 相同动态类型的新对象
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) }
}
答案 0 :(得分:0)
尝试super.init(timeInterval:0, since:d)