如何用包含日期的字典对数组进行排序? [英] How to sort an Array with Dictionaries which include date?

查看:57
本文介绍了如何用包含日期的字典对数组进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Swift项目中,有一个ArrayDictionaries.每个Dictionary包含dateString.如何从最新到最旧使用新的Arraydate?谢谢!

In my Swiftproject there is an Array with Dictionaries. Each Dictionarycontains a String of date. How can I get a new Arraywith datefrom newest to oldest? Thanks!

var array = [["date":"2016-02-12","title":"1"],["date":"2014-05-12","title":"2"],["date":"2016-06-18","title":"3"],["date":"2015-09-17","title":"4"]]

推荐答案

像这样:

let array2 = array.sorted {$0["date"]! < $1["date"]!}

这篇关于如何用包含日期的字典对数组进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆