关闭循环?

时间:2017-02-16 10:19:54

标签: ios loops swift3 closures

我在使用此代码时遇到了一些问题:

let earlyDate = startDate.dateByAddingHours(-12)
var currentDayInt = earlyDate.daysBeforeDate(Date()) + 1;
var currentDayDate = Podometer.getMidnight(Date());
var currentDayDateServer = Podometer.getNoon(Date());
var wantedDateEnd = currentDayDate.dateByAddingHours(24)

for i in (0..<currentDayInt).reversed() {
   self.getSteps(startDate, challengeEndDate: endDate, wantedDateStart:currentDayDate, wantedDateEnd: wantedDateEnd, completion: { (stepNumber) -> Void in
         self.realmSteps.cacheSteps(user_id: self.user_id, day: i + 1, date: currentDayDateServer, nb_steps: Int(stepNumber))
   })
   wantedDateEnd = wantedDateEnd.dateByAddingHours(-24)
   currentDayDateServer = currentDayDateServer.dateByAddingHours(-24)
   currentDayDate = currentDayDate.dateByAddingHours(-24)
}

我想在一天的时间内从iPhone计步器中获取步数。这是有效的,但问题来自循环中的日期。

他们奇怪地更新了,我的缓存做了一些奇怪的事情。我认为这是因为我在循环中使用闭包这一事实。我该如何解决? (如果我在闭包中添加一个新值,则不会更新)。

0 个答案:

没有答案