GitXplorerGitXplorer
h

SwiftObjCBridge

public
45 stars
2 forks
0 issues

Commits

List of commits on branch master.
Unverified
1aba3cdb23e006ebffd474ed4d5bb7945faf4196

Travis: Do not build on Linux

hhelje5 committed 6 years ago
Unverified
a44194141d1bdf42b2980434944076c7a024b326

Travis: Use Swift 5.0 release

hhelje5 committed 6 years ago
Unverified
8fbe28d6fcc54d25aa8c8dcd453ac65bc9466c0c

README: Ptr to blog

hhelje5 committed 6 years ago
Unverified
3d0e2a67b3dd9fecf44c887faf9a3a1dfddfd57c

Fixup README

hhelje5 committed 6 years ago
Unverified
8a24fb12bc1fa3d91a6f722635b3b27ef175f514

Small README fixes

hhelje5 committed 6 years ago
Unverified
6b850389f954a55c7008a316001dc23132a3c006

Travis: Add setup

hhelje5 committed 6 years ago

README

The README file for this repository.

Swift - Objective-C Bridge

Swift5 macOS

Part of this blog post: @dynamicCallable Part 2: Swift/ObjC Bridge.

In December we demonstrated how to use the new Swift 5 Dynamic Callable feature to run Unix commands as Swift functions, like shell.ls(). Today we implement our very own Swift / Objective-C bridge using the same!

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.

Swift also runs on Linux, but it doesn't come with the Objective-C runtime and bridging features. Using the approach shown here with either libFoundation or GNUstep you could also combine Swift and Objective-C on Linux.

This is what we want to end up with:

let ma = ObjC.NSMutableArray()
ma.addObject("Hello")
  .addObject("World")
print("Array:", ma.description())

For demonstration purposes only: This is just a demo showing what you can do with @dynamicCallable, nothing more! (we also cheat a few times and silently rely on builtin bridging.)

Install a Swift 5 Snapshot

For this to work, you need to have Swift 5 installed. As of today Swift 5 hasn't been released yet, but Apple is providing prebuilt Swift 5 development toolchains over at: swift.org, and you can also use the Xcode 10.2beta. Just install the toolchain, and select it in the Xcode "Toolchains" menu.

If you are living on the commandline, make sure to call export TOOLCHAINS=swift to get access to the selected version.

To try out the samples below, you can either open a Swift 5 Playground or create a command line tool project project in Xcode.

Links

Who

Brought to you by ZeeZide. We like feedback, GitHub stars, cool contract work, presumably any form of praise you can think of.