zhiming jiang zhiming jiang - 1 year ago 106
iOS Question

string like "2016-06-06" to Date object in Swift 3

I am new to swift 3, the way I found is

extension Date
init(dateString:String) {
let dateStringFormatter = DateFormatter()
dateStringFormatter.dateFormat = "yyyy-MM-dd"
dateStringFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") as Locale!
let d = dateStringFormatter.date(from: dateString)!
self(timeInterval:0, since:d)

in self(timeInterval:0, since:d) raise error Cannot call value of non-function type 'Date'
also I doesn't see this error before. Anyone please help me and explain it

Answer Source

Change to: self.init(timeInterval:0, since:d)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download