I am trying to build a bridge between flutter and swift in iOS for a little widget. The problem I am facing is converting the DateTime.now().toIso8601String into a usable Date Object in Swift, this is how my code looks like:
let shared = sharedDefaults?.object(forKey: "widgetData") as? [String: String] ?? [String: String]()
let isoDateFormatter = ISO8601DateFormatter()
isoDateFormatter.timeZone = TimeZone(abbreviation: "GMT")
isoDateFormatter.formatOptions = [.withInternetDateTime,
.withDashSeparatorInDate,
.withFullDate,
.withFractionalSeconds,
.withColonSeparatorInTime]
let realDate = isoDateFormatter.date(from: shared["start"]!)
print(realDate)
print(shared["start"]!)
flutterData = FlutterData(title: shared["title"]!,
comment: shared["comment"]!,
end: nil,
start: realDate ?? Date())
I have built in a fallback to the current Date() but I don't seem to manage to convert the DateTime String to a swift Date Object
here is how it looks like when printed:
2021-09-18T14:56:50.606258