Recursive UpdateKit Example

An example of how to integrate UpdateKit into your recursive Shortcuts


Description

Recursion is a powerful tool in programming. It's the idea that an algorithm can call itself. Factorial is a great example of this:

4! = 4 * 3!

3! = 3 * 2!

2! = 2 * 1!

1! = 1

iOS Shortcuts also support recursion, in other words, a Shortcut call call itself. This has a variety of applications.

The dangerous thing is that if a Shortcut supports UpdateKit, it might try to run UpdateKit each time it calls itself. UpdateKit takes a few seconds to run, so this process could take a long time.

This Shortcut is an example of how to handle recursion well with UpdateKit.

It works like this. All recursive algorithms have what’s known as an exit condition. It’s basically an if-statement that checks whether or not to recurse again. Recursive Shortcuts don’t have to have an exit condition, but they should. You should put all your UpdateKit actions in the branch of the exit condition that’s called when it’s not about to recurse.

Download the Shortcut, play around with it, see how it works, maybe even tweak it a little bit, then integrate the ideas into your own Shortcut. No need to credit me.


Latest Release Notes

1.2.0 - April 26, 2020, 2:44 p.m.

Added proper iOS 13 support


Past versions