Tenir compte de ce code:intervallomètre pas de tir
import Foundation
import PlaygroundSupport
class Test
{
var interval:Timer?
var counter = 0
func start()
{
print("Starting ...")
interval = Timer.scheduledTimer(withTimeInterval: 1, repeats: true)
{
timer in
self.counter += 1
print(self.counter)
if (self.counter < 10) { return }
self.interval?.invalidate()
self.interval = nil
print("Done!")
PlaygroundPage.current.finishExecution()
}
interval?.fire()
}
}
PlaygroundPage.current.needsIndefiniteExecution = true
var test = Test()
test.start()
L'exécution de cette aire de jeu dans Xcode 8.3.3 mais l'intervalle ne démarre jamais. Qu'est-ce qui me manque?
Je ne suis pas à mon ordinateur en ce moment, mais google "aire de jeux indéfinie d'exécution" – Kevin
@Kevin J'ai mis à jour mon exemple selon https://stackoverflow.com/questions/24058336/how-do-i-run-asynchronous -callbacks-in-playground # 24066317 pour Playground mais toujours pas de tir. – BadmintonCat
Fonctionne bien pour moi quand je copie et colle votre code. – Kevin