I need to persist a closure but it doesn't seem possible with any persistence methods available in Swift and I can't seem to find any information.
Since the "Code" part of the closure is fixed (compiled) there is no need to persist it, you only need to keep a reference to it with a keyword or some other identifier. This can be achieved using a dictionary with references to functions for example (i.e. a factory of functions).
What actually needs persistence are the variables that are captured by the closure. This is equivalent to parameters of a function.
So basically, you should probably approach your problem differently and define a set of function keywords and parameter lists. You can easily persist those and later "execute" the data by passing the parameters to the factory of functions associated with the keywords.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With