//
//  TrackKit
//
//  Created by Jelle Vandebeeck on 21/03/16.
//

extension String {

    func isoDate() -> Date? {
        return DateFormatter.isoDateFormatter.date(from: self)
    }

    func isoDateWithMilliseconds() -> Date? {
        return DateFormatter.isoDateFormatterWithMilliseconds.date(from: self)
    }

}

extension DateFormatter {

    fileprivate static let isoDateFormatter: DateFormatter = {
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
        formatter.timeZone = TimeZone(abbreviation: "UTC")
        return formatter
    }()

    fileprivate static let isoDateFormatterWithMilliseconds: DateFormatter = {
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
        formatter.timeZone = TimeZone(abbreviation: "UTC")
        return formatter
    }()

}

//
//  TrackKit
//
//  Created by Jelle Vandebeeck on 21/03/16.
//

extension String {

    func isoDate() -> Date? {
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
        formatter.timeZone = TimeZone(abbreviation: "UTC")
        return formatter.date(from: self)
    }

    func isoDateWithMilliseconds() -> Date? {
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
        formatter.timeZone = TimeZone(abbreviation: "UTC")
        return formatter.date(from: self)
    }

}

--- 
+++ 
@@ -7,17 +7,29 @@
 extension String {
 
     func isoDate() -> Date? {
+        return DateFormatter.isoDateFormatter.date(from: self)
+    }
+
+    func isoDateWithMilliseconds() -> Date? {
+        return DateFormatter.isoDateFormatterWithMilliseconds.date(from: self)
+    }
+
+}
+
+extension DateFormatter {
+
+    fileprivate static let isoDateFormatter: DateFormatter = {
         let formatter = DateFormatter()
         formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
         formatter.timeZone = TimeZone(abbreviation: "UTC")
-        return formatter.date(from: self)
-    }
+        return formatter
+    }()
 
-    func isoDateWithMilliseconds() -> Date? {
+    fileprivate static let isoDateFormatterWithMilliseconds: DateFormatter = {
         let formatter = DateFormatter()
         formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
         formatter.timeZone = TimeZone(abbreviation: "UTC")
-        return formatter.date(from: self)
-    }
+        return formatter
+    }()
 
 }
Optimize the use of the date formatters.
