let expecation = expectationWithDescription("do tasks")
for i in 0...40 {
let afterTiming = 0.3 * Double(i)
let startTime = CFAbsoluteTimeGetCurrent()
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(afterTiming * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
print("\(afterTiming) - \(timeElapsed) : \(i)")
}
}
waitForExpectationWithTimeout(14)
after 30 executes its almost a second off, and console start acting weird with showing two and two print lines simultaneously
9.0 - 9.88806998729706 : 30
9.3 - 9.88832598924637 : 31
Is there any way for an XCTest
to get closer to actually doing the requests "on correct time"? Like getting the request that should be done after 9 seconds not being done after 9.88 seconds..