Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile swift library project into .so file?

I'm new to XCode and Objective C / Swift. I'm trying to make a Swift library project that doesn't depend on cocoa or anything. So it's just Swift files. What type of project should I be creating (I'm assuming there are multiple ways of doing this? How do I need to configure the project so that it builds to a .so file? And finally, how do I build it to a .so file?

I'm using Xcode6-beta.

like image 334
spierce7 Avatar asked Oct 31 '22 22:10

spierce7


1 Answers

You can create a Swift library for iOS by creating a new Xcode Project and selecting iOS/OS X -> Framework & Library -> Cocoa Touch Framework and then setting the language to Swift on the next screen.

Once this project has been created you are not required to link against the Cocoa frameworks, and can remove any references to them if needed.

Upon compiling this project Xcode will create a .framework folder in your build directory which contains a dynamic library which you should then be able to link against. Note however that I haven't had any success myself yet at linking directly against this file, even though it appears to be a standard dynamic library.

In terms of using this shared object file on Android I believe you will be out of luck, as the Swift language (much like Objective-C) requires a runtime library which is simply not available on other platforms at this time.

like image 97
melbyruarus Avatar answered Nov 08 '22 05:11

melbyruarus