New Xcode 7.3: Swift NSDate extension with nullable convenience init crashes EXC_BAD_ACCESS

Viewed 436

I have this NSDate extension with nullable init, which worked fine all the time, until I updated to newly released Xcode 7.3.

Now it crashes with EXC_BAD_ACCESS.

extension NSDate
{
    convenience init?(dateString:String, formatString:String?)
    {
        let dateFormatter = NSDateFormatter()
        dateFormatter.dateFormat = formatString

        let newDate:NSDate? = dateFormatter.dateFromString(dateString)

        if let newNewDate = newDate
        {
            self.init(timeInterval:0, sinceDate:newNewDate)
            return
        }

        print("ERROR: Wrong format [\(formatString)] for date [\(dateString)]")
        return nil
    }
}

let d1 = NSDate(dateString: "2016-01-01 11:00:00", formatString: "yyyy-MM-dd hh:mm:ss") // OK
let d2 = NSDate(dateString: "qq123", formatString: "qwe") // EXC_BAD_ACCESS

Do you have any possible solution for this? Cannot figure out - am I abusing extension of NSDate somehow?

1 Answers
Related