How To Sort Date Array In Swift? : I Want To Sort Array That Is Full Of Month with year example : ["Nov 2019","Apr 2020","MAR 2018","Jan 2018","May 2018"](non sorted) to -> ["Jan 2018","Mar 2018","May 2018","Nov 2019","Apr 2020"](sorted) like this...

u also give code in any language i convert to swift :)


    func sortDate( arr : inout [String]) {
        let months : [String] = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"]
        for i in 0..<arr.count{
            for j in i..<arr.count{
                let string1 = arr[i]
                let string2 = arr[j]
                let month1 = String(string1[string1.startIndex...string1.index(string1.startIndex, offsetBy: 2)])
                let month2 = String(string2[string2.startIndex...string2.index(string2.startIndex, offsetBy: 2)])
                if months.index(of: month1.lowercased())! > months.index(of: month2.lowercased())! {
                    let temp = arr[i]
                    arr[i] = arr[j]
                    arr[j] = temp
                }
            }
        }
        for i in 0..<arr.count{
            for j in i..<arr.count{
                let string1 = arr[i]
                let string2 = arr[j]
                if (string1[string1.index(before: string1.endIndex)..<string1.endIndex] as NSString).intValue < (string2[string2.index(before: string2.endIndex)..<string2.endIndex] as NSString).intValue {
                    let temp = arr[i]
                    arr[i] = arr[j]
                    arr[j] = temp
                }
                
            }
        }
        
    }

This is I Tryed.. But Its Not Work Properly..

This is input : 
      ["Jan 2020", "Feb 2018", "Mar 2018", "Apr 2018", "May 2018", "Jun 2018", "Jul 2018", "Aug 2018", "Sep 2018", "Oct 2018", "Nov 2018", "Jun 2019", "Feb 2019", "Jul 2019", "Apr 2019", "Aug 2019", "Sep 2019", "May 2019", "Oct 2019", "Jan 2019", "Mar 2019", "Nov 2019"]


Output Is :
   
["Jan 2019", "Feb 2019", "Mar 2019", "Apr 2019", "May 2019", "Jun 2019", "Jul 2019", "Aug 2019", "Sep 2019", "Oct 2019", "Nov 2019", "Jul 2018", "Mar 2018", "May 2018", "Aug 2018", "Feb 2018", "Sep 2018", "Oct 2018", "Apr 2018", "Nov 2018", "Jun 2018", "Jan 2020"]