In this blog post I will show how these functions can be implemented in Swift on the native side and how to make them available in the
The first step is to provide native functionality for intervals and timeouts. We create a new Swift class
JSPolyfill for this and define functions to allow creation and removal of repeating and non-repeating timers. The callback value is of type
JSContext lets us load code blocks as polyfills into the context. However this only works with Objective-C blocks, not with Swift closures. In order to export a closure we annotate the closure with the
@convention(block) attribute to bridge it to an Objective-C block.
Add the following method to our
JSPolyfill class which creates the four missing functions for supporting timeouts and intervals.
Now all that’s left to do is to call the
registerInContext method after we instantiate
Feel free to provide feedback and ask questions.