Thursday, January 31, 2019 [Tweets] [Favorites]

Swift-ObjC Bridge Using @dynamicCallable

Helge Heß:

Of course Swift already has Objective-C integrated on the Apple platforms, directly supported by the compiler, as well as the associated bridging runtime. Yet using Dynamic Callable you can actually build something similar at the library level, and we want to show you how that would look like.

[…]

You may have wondered that arrayByAddingObject: instead of addObject: was used to demo the thing. That had a reason 😜 Our signatures deal with methods returning object values, but addObject: is a Void method. If we invoke it, we crash, because ARC will attempt to release the non-existing result.

It’s a fun demo, but real-world bridging is complicated by memory management, error parameters and exceptions, non-object types, etc.

Previously: @dynamicCallable: Unix Tools as Swift Functions.

Comments

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

Leave a Comment