BergP BergP - 3 months ago 12
Swift Question

Swift: how can I create external interface for static library (public headers analog in Objective-C .h)

I need to create a static library with Swift,
and I need to know how can I implement interface for the library.

In Objective-C I can mark needed headers as public in build phases,
but there is not any headers and any interfaces in Swift.

What should I do with Swift?


Simply put: you don't.

Swift is not a language that separates headers and implementations. When you create a library or framework based on Swift and only for consumption by Swift, the Xcode default build setting of DEFINES_MODULE already does the job for you. This will create a .swiftmodule file, which will be used by import in other Swift projects.

If you want your code to be importable from Objective-C though, you might want to check if the SWIFT_INSTALL_OBJC_HEADER build setting is also enabled (which it is by default for frameworks as far as I know). Then the Swift compiler will generate a <ProductName>-Swift.h file for you, which you can import in Objective-C code to access your Swift classes and functions.