Loto: { "success": true,"data": { "oID": "64kbbqi8dbxygb00","hafta": 961,"buyukIkramiyeKazananIl": "","cekiListarihi": "11/04/2015","cekiListuru": "SAYISAL_LOTO","rakamlar": "03#02#48#16#15#08","rakamlarNumaraSirasi": "02 - 03 - 08 - 15 - 16 - 48","devretti": false,"devirsayisi": 0,"bilenKisiler": [ { "oID": "64kbbxi8dbxyg403","kisiBasinaDusenIkramiye": 7.35,"kisiSayisi": 185712,"tur": "_BILEN" },{ "oID": "64kbbxi8dbxyg402","kisiBasinaDusenIkramiye": 53.05,"kisiSayisi": 9146,"tur": "_BILEN" },{ "oID": "64kbbxi8dbxyg401","kisiBasinaDusenIkramiye": 4532.2,"kisiSayisi": 142,"tur": "_BILEN" },{ "oID": "64kbbxi8dbxyg400","kisiBasinaDusenIkramiye": 1528438.75,"kisiSayisi": 1,"tur": "_BILEN" } ],"buyukIkrKazananIlilceler": [ { "il": "10","ilVIEw": "BAliKESÄ°R","ilce": "01001","ilceVIEw": "AYVAliK" } ],"kibrisHasilati": 51127,"devirTutari": 0.09,"kolonSayisi": 10537872,"kdv": 1599672.97,"toplamHasilat": 10537872,"hasilat": 8938199.03,"sov": 893819.9,"ikramiyeEH": 8044379.129999999,"buyukIkramiye": 1528432.03,"haftayaDevredenTutar": 0 } }
所以我的词典像<“11042015”,Loto>我想按照loto对象的“hafta”属性对这本词典进行排序.
我怎样才能做到这一点?请帮我!
解决方法 如果Loto是一个具有hafta属性的对象,您可以通过将字典传递给sorted函数以及一个告诉它如何对条目进行排序的闭包来对字典进行排序:sorted(dict) {sorted(dict.values) { .hafta < .hafta }.1.hafta < .1.hafta }
($0.1和$1.1,因为字典作为一系列键/值对出现 – 您希望按值的属性排序,即元组条目1)
注意,这将返回一个排序数组,类型为[(String,Loto)]对,而不是字典(因为Swift字典是无序的).
(如果Loto不是真正的对象而是另一个字典,你可能需要{$0.1 [“hafta”]< $1.1 [“hafta”]} - 这实际上取决于你如何保存你的数据 - 好消息你不需要担心选项,因为它们可以与<)比较 如果您不需要密钥,只需对值进行排序:
这会给你一个类型为[Loto]的排序数组
总结以上是内存溢出为你收集整理的ios – Swift按字段属性排序字典全部内容,希望文章能够帮你解决ios – Swift按字段属性排序字典所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)