一次創建幾個DispatchQueue.main.asyncAfter方法,我想有位置的地圖,一個上繪製相繼與各間在1秒內繪製的位置,但它並不完全工作。這是我到目前爲止有:斯威夫特3
@IBAction func playButtonPressed(_ sender: Any) {
var index = 0.0
var i = 0
var j = 0
while i < sites.count {
while j < sites[i].count {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0*index) {
self.plot(day:i,site:j)
}
j += 1
index += 1
}
j = 0
i += 1
}
}
func plot(day:Int,site:Int) {
for letter in glossary {
let siteToPlot = sites[day][site]
if let location = letter[siteToPlot] {
setUpMap(name: location.name!, lat: location.lat!, long: location.long!)
}
}
}
的方式我有它設置,在for循環將會有一個名爲在DispatchQueue.main.asyncAfter方法,但每個項目將被派往每次一秒鐘後項。首先爲0秒後,然後1,然後是2等
它似乎並不該地塊函數參數但是保存,作爲第一個時間點的劇情函數被調用,天與本站值是9和0,這是循環結束時的值。
可能重複的[通過值關閉?](http://stackoverflow.com/questions/31565832/pass-value-to-closure) –