Thursday, December 27, 2018 [Tweets] [Favorites]

@dynamicCallable: Unix Tools as Swift Functions

Always Right Institute:

A new feature in Swift 5 are Dynamic Callable’s. We combine this with the related Dynamic Member Lookup feature to expose the filesystem and Unix shell commands as regular Swift objects and functions.


This is intended as a demo. It should work just fine, but in the name of error handling and proper Swift beauty, you might want to approach forking processes differently 🤓


An obvious limitation is that both features are statically typed. You can’t lookup one function thats returns an Int, and another function which returns a String. You have to tell the compiler in advance what type you expect.


Another limitation is that the reverse is not possible, i.e. you cannot lookup a Callable for a Swift function and dynamically invoke it via m.dynamicallyCall(withArguments:).

Previously: Schema-less Database With Dynamic Swift, Exploring @dynamicMemberLookup.


Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment