Dispatch Macros

Each of these runs your function when the licence is valid, and something harmless when it is not. Which one you want depends on whether your function takes arguments, returns a value, or needs to be stored as a pointer.

TIL_DISPATCH

Signature
TIL_DISPATCH(pkg, fn)

Calls fn() when licensed. When not, calls an inert stub that does nothing. fn takes no arguments and returns nothing.

Objective-C
TIL_DISPATCH("com.example.mytweak", install_my_hooks);

TIL_DISPATCH_OR

Signature
TIL_DISPATCH_OR(pkg, fn, fallback)

As above, but you choose what runs when unlicensed, instead of nothing happening. Handy when a paid feature has a simpler free counterpart inside the same tweak. If the whole tweak is free, ship it as its own package instead of wiring a fallback for it.

Objective-C
TIL_DISPATCH_OR("com.example.mytweak", full_feature, basic_feature);

TIL_DISPATCH_CALL

Signature
TIL_DISPATCH_CALL(pkg, fn, fallback, ...)

For functions that take arguments and return a value. The arguments are forwarded to whichever of the two is selected, so both must have the same signature.

Objective-C
int width = TIL_DISPATCH_CALL("com.example.mytweak",
                              premium_width, default_width, view);

TIL_DISPATCH_FN

Signature
TIL_DISPATCH_FN(pkg, fn, fallback)

Resolves to the function pointer without calling it, for storing in a struct or passing as a callback. The selection happens where the macro is written, so the pointer handed on is already the right one.

What these are for

Locking features out of an unlicensed copy. A determined attacker can get past them; most people will not bother.