[{ msg = "Hi This is Jecky"; name = Susheel; sender = 77; timestamp = 1464241769520; username = susheel; },{ msg = Dubai; name = Jecky; sender = 78; timestamp = 1464246547147; username = Jecky; },{ msg = "How are you ?"; name = Susheel; sender = 77; timestamp = 1464243480381; username = susheel; },{ msg = "Aje dekhai nai"; name = Jecky; sender = 78; timestamp = 1464244974198; username = Jecky; }]
>我有这样的阵列.我想在swift 2.3或最新版本的swift中使用时间戳对这个数组进行排序.任何人都可以帮助我吗?
解决方法
let array=[ [ "msg":"Hi This is Jecky","name":"Susheel","sender":77,"timestamp":1464241769520,"username":"susheel",],[ "msg":"Dubai","name":"Jecky","sender":78,"timestamp":1464246547147,"username":"Jecky",[ "msg":"How are you ?","timestamp":1464243480381,[ "msg":"Aje dekhai nai","timestamp":1464244974198,] print("array = \(array)") let sortedArray=array.sort { (obj1,obj2) -> Bool in return (obj1["timestamp"] as! Double) < (obj2["timestamp"] as! Double) } print("sortedArray = \(sortedArray)")