Embedding Silver in Apple Swift Projects

Is it possible to interop between an Apple Swift project and Silver? I’m working at a company with a massive ObjC/Swift codebase using Bazel, and my team wants to be able to iterate faster. I’m thinking we could have some files compiles to Silver and then have a RmObject’s VM running in the app to get a hot reload working.

And on that note, is there a Rem supported VM? I looked at the backends Compiler Back-Ends and couldn’t find anything. But it seems like all languages supported are being compiled into the same IL code.

Thanks! I just discovered this suite today!

Hi Joe,

you don’t need a VM or anything*. if you create a Static Library project from the Cocoa tab of the New Project dialog, that will be a 100% native “Objective-C”-style Cocoa library that you can use from Xcode. When you compile it, you’ll get a .a binary and a .h header file that you can just add to your Xcode project as if they are created in Objective-C. Do make sure you set the “-ObjC” linker flag om Xcode, newer versions dont seem to set that by default anymore.

(*that said, you want to host .NET code in a Mac app, thats also possible. But rarely needed).

We compile to IL only if you build .NET projects; Coocal projects compile straight to native Objective-C runtime code (and Java/Android ones compile to Java JVM Byte Code).

hth!

Awesome! Welcome to Elements – and don;t hesitate too ask if you have any further rquestions.

1 Like

Got it! Very cool. I made a public class in a Java file and my Swift code was able to use it (using Fire to build an iOS app). How is that accomplished when you compile a static .a .h library? Is the Java file being transpiled to ObjC or is it going to the IL step?

Could that be a route to get hot reloading working? That’s the main thing I want to use this Silver for.

There’s no transpiling involved, and no IL.

Almost every compiler works in two steps (a) parse the language syntax into a more abstract representation of what the code does, and then turn that abstraction into the output code (being it CPU-native code, IL, or whatever).

Elements does the same, except that it can “read” code in six different languages (even mixed) and turn it into that abstraction level, and form there it an turn it into several out out formats (IL, JVM, as well as native).

I thought we had a blog post that explains this in more details, but I cant find that now right now; in the mean time, I found this one:

Maybe, but probably not. can you explain a bit more what you need to do/are trying to achieve?

1 Like