首页 > 解决方案 > Sorting dates with swift

问题描述

How can I get a date from an array if I don't have all the parts of the date.

I have a dictionary with different dates and try to get all dates from it with the month of June.

let dict = ["15-06-2019" : "red",
            "19-10-2019" : "green", 
            "05-08-2018" : "yellow", 
            "20-06-2019" : "orange"]

标签: iosswiftxcodedate

解决方案


利用filter

let dict = ["15-06-2019" : "red", "19-10-2019" : "green", "05-08-2018" : "yellow", "20-06-2019" : "ornge"]
let filtered = dict.filter { $0.key.range(of: "-06-") != nil }

推荐阅读