ios - 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"]
解决方案
利用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 }
推荐阅读
- sql - PostgreSQL 如何使用 with as
- php - 重音字符问题(ADODB + MySQL + PHP)
- arrays - Excel v.16 VBA SeleniumBasic array.length 等效于 Selenium
- python - 如何将 blob 文件转换为特定格式?
- html - Chrome 和 Edge 不支持输入或选择标签的“书写模式”
- html - 有没有办法在 WKWebView 中加载本地图像?
- python - 如何连接 Pandas 中的两个字符串列,但不包括第二个中的重复单词?
- python - Matplotlib 动画子图
- javascript - 在 GAS 中使用数组
- java - Spring Boot 应用程序在本地运行,但 Heroku 在 org.springframework.boot.SpringApplication 上抛出 ClassNotFoundException