Skip to content

Sample code & slides for Swift Glue Code, presented at 360iDev 2016

Notifications You must be signed in to change notification settings

sptramer/360iDev-Swift-Glue-2016

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift Glue Code - 360iDev

Here's the full keynote slides and sample project for Swift Glue Code, presented at 360iDev 2016. This project and slide set covers:

  • How to prepare your Objective-C code for migration
  • A good wrapping strategy in Swift
  • Some information on Swift calling conventions

There's a couple of things mentioned in the talk that are missing from the sample (direct call to Swift) but hopefully they can be added soon!

About the sample code

The sample code is for a CLI (command-line interface) which takes 'points' in a ridiculous, arbitrary coordinate system and can perform some basic operations on them. The scheme for the "coord-procBundle" target has some pre-set values for the command line that you can fiddle with, to run the application and see that it actually works. Play around with it a little bit!

About the .sil, .ir, and .s files:

These files were generated by running

swiftc -emit-[sil|ir|assembly] \
	-sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk \
	-I "/Volumes/VMware Shared Folders/confs/360idev-2016/glue-code/LibCoords/LibCoords/LibCoords-Bridge" \
	-module-name LibCoords \
	Location.swift > Location.[sil|ir|s]

Change your SDK reference and location of the LibCoords-Bridge directory as appropriate.

They have not been annotated themselves, but there are hints in the source code where relevant about which files correspond to where information regarding data layouts or function call parameters were derived from.

How can glue code be improved?

Well, in the talk, I did say that it's boring and costly to write, because you have to throw it away. One thing that I wanted to do was figure out to way to write a tool to insert into the compiler chain between either AST and SIL, or SIL and IR emission, which would examine a provided type name and automatically generate glue code for you. But the truth is that this could just be an @objc annotation, and with well-defined behavior (requiring an ABI) regarding how struct and enum are generated, wrapper types could be generated during the compilation phase.

While this is something that I bet the Swift team is thinking about, please join me in requesting a feature or participating in the swift-evolution mailing list to help the Swift team allow bridging every Swift type into Objective-C!

About

Sample code & slides for Swift Glue Code, presented at 360iDev 2016

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published