Last active
June 17, 2016 07:53
-
-
Save fitomad/769265e7227326b99ac678efda611ac6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Las variables `queue` y `timer` deben estar deblaradas | |
// como variables de la clase para así no perder la | |
// referencia. | |
// | |
// queue es de `tipo dispatch_queue_t` | |
// timer es de tipo `dispatch_source_t` | |
// | |
private func createTimer() -> Void | |
{ | |
self.queue = dispatch_queue_create("com.desappstre.Pomodoro./Timer", DISPATCH_QUEUE_SERIAL) | |
self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, self.queue) | |
let walltime: dispatch_time_t = dispatch_walltime(nil, 0) | |
// Disparamos el temporizador casa 6o segundos | |
// con una demora permitida de 1 segundo | |
dispatch_source_set_timer(self.timer, walltime, 60 * NSEC_PER_SEC, 1 * NSEC_PER_SEC) | |
dispatch_source_set_event_handler(self.timer) | |
{ | |
self.actionForTimer() | |
} | |
} | |
/** | |
Metodo que ejecutar el timer. | |
*/ | |
private func actionsForTimer() -> Void | |
{ | |
// Hacemos algunas cosas chulas... | |
dispatch_async(dispatch_get_main_queue()) | |
{ | |
// Todas las actualizaciones de interface de usuario | |
// aquí por favor :) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment