ios – 如何按升序排序数组swift 2.3

ios – 如何按升序排序数组swift 2.3,第1张

概述[{msg = "Hi This is Jecky";name = Susheel;sender = 77;timestamp = 1464241769520;username = susheel;}, {msg = Dubai;name = Jecky;sender = 78;timestamp = 1464246547147;username = Jecky;}, {
[{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)")
总结

以上是内存溢出为你收集整理的ios – 如何按升序排序数组swift 2.3全部内容,希望文章能够帮你解决ios – 如何按升序排序数组swift 2.3所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1101893.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存