I'm trying to learn how to dispatch computations on a background thread and resultantly update the UI after. When I attempt this in an existing project with Google Maps, "background" followed by "main" is printed once. No more printing occurs, as if the timer does not repeat.
Further, when I create a blank application and add this code in, nothing prints at all.
let queue = dispatch_queue_create("myTimer", nil);
let timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, 1 * NSEC_PER_SEC);
dispatch_source_set_event_handler(timer) {
println("background")
dispatch_async(dispatch_get_main_queue(), { println("main") })
}
dispatch_resume(timer)