Skip to content

Instantly share code, notes, and snippets.

@fitomad
Last active June 17, 2016 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitomad/769265e7227326b99ac678efda611ac6 to your computer and use it in GitHub Desktop.
Save fitomad/769265e7227326b99ac678efda611ac6 to your computer and use it in GitHub Desktop.
//
// 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