3

I wanted to create a separate library that has mostly Objective-C code but also some Swift files. I tried to use Xcode 6's Touch Framework, which worked fine if my deployment target was >= iOS8.0 in final product.

But I need to build for IOS7 and it fails with explanation that linking/loading dylibs are not supported on iOS7.

After that I created static library target, but the problem is it does not support swift files (swift modules).

Any ideas how to make this work for iOS7?

Matej Ukmar
  • 2,157
  • 22
  • 27

1 Answers1

1

After a few days of trying I found the following solution in spite Apple saying static libraries don't support Swift.

If I tried to build static library with swift files build from Xcode failed explaining that 'libtool' does not know -Xlinker parameter (unknown option character `X' in: -Xlinker). The parameter tries to specify Swift module - that as said by Apple is not supported for static libraries.

What I did is I copy/pasted the whole libtool command (that Xcode was trying to use) to terminal, removed all '-XLinker ...' parameters and surprisingly build succeeded from command line.

My static library project included both Objective-C and Swift sources and they were both 'packed' into produced static library!

The only downside was that Swift module was not produced but in my case that didn't matter because Swift was used only internally - I had only Objective C external interfaces.

I think it would be possible also to expose Swift 'interfaces' by copying produced static lib bridging header along the produced static lib.

Matej Ukmar
  • 2,157
  • 22
  • 27