I'm trying to fetch dates from a server response that look like this:
"dateStart": "2019-08-21T14:54:03.285108Z",
"dateEnd": "2019-09-20T06:15:03.285108Z"
As I need only from the date only the day and the month, so the result would be: "08-21" and "09-20"
I did try to filter the resutls, but I'm getting crash:
Thread 1: Fatal error: Can't form Range with upperBound < lowerBound
here is my code:
let startTime = dealStatus["dateStart"] as? String
let startFirst = startTime!.index(startTime!.startIndex, offsetBy: 5)
let endFirst = startTime!.index(startTime!.endIndex, offsetBy: -17)
let startTimeString = startTime![startFirst..<endFirst] // Getting crash here
let endTime = dealStatus["dateEnd"] as? String
let startSecond = endTime!.index(endTime!.startIndex, offsetBy: 5)
let endSecond = endTime!.index(endTime!.endIndex, offsetBy: -17)
let endTimeString = endTime![startSecond..<endSecond]
let startReplaced = startTimeString.replacingOccurrences(of: "-", with: ".")
let endReplaced = endTimeString.replacingOccurrences(of: "-", with: ".")
let startEndDates = "(" + String(startReplaced) + " - " + String(endReplaced) + ")"
//
let orderTitle = ordersResponseArray[indexPath.row]
let catTitle = orderTitle["title"] as? String
cell.titleAndDatesLabel.text = catTitle! + " " + startEndDates
Any help would be extremely appreciated!