我收到的服务回复如下
[["realms": ({
authorizationType = External;
contentPageId = "<null>";
description = "Demo accounts";
externalRegistrationUrl = "<null>";
id = 1;
identifier = Demo;
showDuringSignup = 1;
}), "identifier": MENIISRE, "name": MegaTest, "imageData": < null > , "iconFilename": < null > , "imageDataId": 0, "id": 1, "orderIndex": 0, "altName": < null > ],
["realms": ({
authorizationType = Internal;
contentPageId = "<null>";
description = Test Desc;
externalRegistrationUrl = "<null>";
id = 2;
identifier = TestFB;
showDuringSignup = 0;
}), "identifier": 0012321, "name": TestAccount, "imageData": < null > , "iconFilename": a385bdff - 323 d - 4 a4b - 8019 - 233115 b43b38.png, "imageDataId": 1000019, "id": 2, "orderIndex": 0, "altName": < null > ]]
从上面的回复中,我只能显示' showDuringSignup '为1的记录 .
一个选项是我可以在数组上运行循环并获得所需的结果,但这是一种旧的方式,我想使用高阶函数(例如Filter,Map,flapMap等)
因此,我尝试使用下面的代码
let arrayOfAvailableBanks = arrayOfDictOfBankAccounts.map{$0["realms"].map{($0["showDuringSignup"] as? Int) == 1}}
但我无法得到所需的输入 .
请在这里建议我做错了什么,以及如何只获取'showDuringSignup'为1的那些对象 .
2 回答
好吧,我想我可能已经解码了你提供的回复 .
你需要的是
filter
.你可以试试这个:
你应该使用
filter
,请找到下面的代码,所以整个代码就是这样的