Arrays 如何在swift3中查找同一字典键多次出现的索引?

Arrays 如何在swift3中查找同一字典键多次出现的索引?,arrays,swift3,xcode8,alamofire,Arrays,Swift3,Xcode8,Alamofire,我使用Alamofire+Objectmapper从JSON获取响应,并得到以下数组响应: { "id": 6, "name": "XYZA", "address": "Ireland", "phoneNumber": "", "latitude": 30.678899, "longitude": 18.546789, "operatingDays": [ {

我使用Alamofire+Objectmapper从JSON获取响应,并得到以下数组响应:

{
        "id": 6,
        "name": "XYZA",
        "address": "Ireland",
        "phoneNumber": "",
        "latitude": 30.678899,
        "longitude": 18.546789,
        "operatingDays": [
            {
                "days": [
                    "Sun",
                    "Mon",
                    "Tue",
                    "Wed",
                    "Thu"
                ],
                "times": [
                    "09:00-12:00",
                    "16:00-21:00"
                ]
            },
            {
                "days": [
                    "Fri"
                ],
                "times": [
                    "17:00-22:00"
                ]
            }
        ]
    },
    {
        "id": 7,
        "name": "India",
        "address": "ABCDE",
        "phoneNumber": "",
        "latitude": 27.23333,
        "longitude": 57.8654,
        "operatingDays": [
            {
                "days": [
                    "Sun",
                    "Mon",
                    "Tue",
                    "Wed",
                    "Thu",
                    "Fri"
                ],
                "times": [
                    "08:00-12:00",
                    "17:00-21:00"
                ]
            }
        ]
    }
对于循环使用此代码,我使用以下代码:

if let threeDayForecast = response?.data {
          for forecast in threeDayForecast {
            print(forecast.name ?? "")
            print(forecast.longitude ?? "")
            print(forecast.latitude ?? "")
            print(forecast.operatingDays)
            self.shopLocation.add(forecast.name ?? "")
            self.shopAddress.add(forecast.shopaddress ?? "")
            for operatingDays in forecast.operatingDays! {
              print(operatingDays.days)
              print(operatingDays.times)
              self.operatingDays.add(operatingDays.days)
              self.operatingTime.add(operatingDays.times)
            }
          }
        }
所以你们可以看到,在id值为6时,我们得到了多个相同的键日期和时间。那么,有没有可能知道这是在什么指数下发生的呢?我的意思是,在索引为0的情况下,这发生在关键操作日

所以为了得到这个,我编写了以下代码:

 if (forecast.operatingDays!.count == 2)   {

                    print("The culprit: \(index)")
                  }

所以我需要得到数组的索引,其中包含多个字典。如何可能?

对于id为6的字典,
操作天数
键是两个字典的数组,每个字典都有
天数
时间
键和数组值。没有重复的日期值,也没有相同的时间范围。所以我认为你需要更好地解释“获得多个值相同的关键日期和时间”。在本例中,您希望得到的“索引”是什么?你试过用什么方法来计算它?编辑你的问题,不要在评论中添加额外的细节。一旦你这样做了,它将帮助人们帮助你,可能会有人帮助你。@CRD请查看编辑。如果你有一个字典数组,那么每个字典都有一个键
operatingsDays
,其值为数组。您想在字典的外部数组中查找索引,其中键的数组包含多个元素?你试过什么?一个循环,一个标准的方法,还有别的吗?为什么不起作用?