Wszystkie przykłady, które widziałem przy użyciu "NSTimer.scheduledTimerWithTimeInterval" w Swift pokazują przy użyciu parametru "target: self", ale niestety to nie działa bezpośrednio na Swift Playgrounds.NSTimer.scheduledTimerWithTimeInterval na Swift Playground
Playground execution failed: <EXPR>:42:13: error: use of unresolved
identifier 'self'
target: self,
Oto przykład mowa powyżej, które prowadzi do błędu:
func printFrom1To1000() {
for counter in 0...1000 {
var a = counter
}
}
var timer = NSTimer.scheduledTimerWithTimeInterval(0,
target: self,
selector: Selector("printFrom1To1000"),
userInfo: nil,
repeats: false
)
timer.fire()
W moim przypadku muszę naciskać serwis internetowy po każdych 5 minutach. Czy byłoby dobrym rozwiązaniem użycie tego kodu? –