如何将最后一项附加到swift3中的数组?

时间:2017-06-25 15:48:37

标签: ios iphone swift3 xcode8

我正在使用两个数组,即dateArray和combinedArray。 dateArray的值附加到comBinedArray。为此,我使用以下代码:

var dataArray = [Any]()
print(self.yourArray)
if let threeDayForecast = end.travelShopsData {
    for forecast in threeDayForecast {
        var index: Int = (threeDayForecast as NSArray).index(of: forecast)
        if self.dateArray.count != 0 {
            self.combinedArray.append(self.dateArray)
            print("combinedArray: \(self.combinedArray)")
            print("combinedArray count: \(self.combinedArray.count)")
        }
        self.dateArray.removeAll()
        self.nameArray.append(forecast.name as Any)
        self.addressArray.append(forecast.address as Any)
        dataArray.append(forecast.cashPointOperatingDays as Any)
        print(forecast.name as Any)
        print(forecast.address as Any)
        print(forecast.phoneNumber as Any)
        print(forecast.latitude as Any)
        print(forecast.longitude as Any)
        print(forecast.cashPointOperatingDays as Any)
        for var i in 0...forecast.cashPointOperatingDays.count/2 {
            var cashPointArray = forecast.cashPointOperatingDays[i ] as? [String: String]
            let retrieveArray = cashPointArray?["operatingDay"]
            self.dateArray.append(retrieveArray)
            print(i)
            print("Data Array: \(self.dateArray)")
            var joiner = ":"
            let str = self.dateArray.flatMap { $0 as? String }.joined()
            print("joinedStrings: \(str)")
        }
    }
}

但问题是dateArray有7个元素,但是在追加到combinedArray之后才是真的。 combinedArray只包含6个元素。上面的代码出了什么问题?

0 个答案:

没有答案