【发布时间】:2017-06-23 08:51:44
【问题描述】:
For example, I have a json response of array type where the second key in each array has same value. The count of the array is dynamic but I need to check everytime, if that particular key value is same in all the arrays, i need to hide a label.
"loadable": [
{
"position": {
"positionType": "XXX",
"thirdKey": 1,
"fourthKey": 1,
},
},
{
"position": {
"positionType": "XXX",
"thirdKey": 1,
"fourthKey": 1,
},
},
{
"position": {
"positionType": "XXX",
"thirdKey": 1,
"fourthKey": 1,
},
{
"position": {
"positionType": "XXX",
"thirdKey": 1,
"fourthKey": 1,
},
}
}
]
这里我想检查关键 positionType == "XXX" 的所有值,然后我需要隐藏一个标签。请迅速给出答案。
【问题讨论】:
-
"请尽快给出答案。"到目前为止,您尝试过什么?
-
for loadables { if loadable.position?.positionType == "XXX" { footer.labelTitle.isHidden = true }
-
现在得到 4 个数组,其中所有值都是 XXX。但是我尝试的代码设置为true,即使有一个XXX和XXX以外的任何其他值
-
loadables 是 Loadable 类的 var,它是 NSManagedObject。 var loadables: [Loadable] = [] @
-
@vinny 然后显示 Loadable 的声明
标签: ios arrays json swift swift3