Skip to content

Instantly share code, notes, and snippets.

@theoknock
Last active February 5, 2022 21:52
Show Gist options
  • Save theoknock/76cbed7470d146e9d351a30590f64b9a to your computer and use it in GitHub Desktop.
Save theoknock/76cbed7470d146e9d351a30590f64b9a to your computer and use it in GitHub Desktop.
Bitwise branching
static long (^(^animate)(long))(void(^__strong)(long *)) = ^ (long duration) {
__block typeof(CADisplayLink *) display_link;
__block long frames = duration;
return ^ long (void (^__strong animator)(long *)) {
display_link = [CADisplayLink displayLinkWithTarget:^{
frames >>= 01;
return
((frames & 01) &&
^ long {
animator(&frames);
return active_component_bit_vector;
}())
||
((frames | 01) &&
^ long {
printf("COMPLETE\n");
[display_link invalidate];
return active_component_bit_vector;
}());
} selector:@selector(invoke)];
[display_link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
return active_component_bit_vector;
};
};
/*
*/
animate(30)(^ (long * frame) {
printf("%ld\n", *frame);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment