Static Linking with Swift, XCode6-Beta
To answer my own question after some discussion in the comments, it is simply not possible to build static libraries that include Swift code yet. I'm writing this as of Beta 4, and the release notes still say, under "Known issues in Xcode 6 beta 4":
Xcode does not support building static libraries that include Swift code. (17181019)
Static Library and Swift
As of Xcode 9 beta 4, Xcode natively supports static libraries with Swift sources.
Why do we have this confusing setup about Static Library and Framework in Xcode
There are many concepts that must be clear
Libraries have two categories based on how they are linked to the executable file
- Static library
.a
,.so
. link at compile time. wiki - Dynamic libraries
.dylib
.dll
etc. link at runtime. only apple can use it for iOS for some safe reason, we cannot build this.
ps, a special kind in apple platform
Text Based .dylib
stubs — .tbd
Framework
Framework is a package that can contain resources such as dynamic libraries, strings, headers, images, storyboards etc.
vs Libraries, Framework has more features
Framework also has static and dynamic
iOS 8 later, we can use a dynamic framework, why Apple releases this. maybe Extension and App share code
this Dynamic Framework for iOS is named embedded frameworks, because when we build the app copy the framework in app bundle.
so the embedded framework is different from system dynamic Frameworks like UIKit.Framework
Why there's no "Dynamic Library" option?
the embedded library is allowed with the Framework
option, but dynamic framework shared in muti app is also not allowed
Given that we can already link framework statically, why do we still need a "Static Library"? (isn't StaticFramework = StaticLibrary + Bundle? )
well, Xcode not only support Objective-c and Swift, but also support C, C++ which may use the static library
Linking the correct variant of an iOS static library using Xcode
Ok, so when linking against a static iOS library, you need to know that:
It does not matter which .a file you add in the Build Phases - Link Binary With Libraries panel. Any of the four .a files will do, it only takes the file name, not its path.
To actually differentiate between library variants for Debug/Release Device/Simulator, you need to specify the correct library paths in the Build Settings - Library Search Paths.
Finding the right way to include static libraries in Xcode
I solved my problem by including sqlite3.c and sqlite3.h from sqlite.org so every wrapper works fine.
Related Topics
How to Delete a Child from Firebase (Swift)
How to Get Uitouch Location from Uigesturerecognizer
Unknown Class in Interface Builder
iOS Input Focused Inside Fixed Parent Stops Position Update of Fixed Elements
How to Disable User Interaction on Mkmapview
_Unused Flag Behavior/Usage (Gcc with Objective-C)
Uiscrollview Zooming with Auto Layout
Watchkit: Unable to Find Interface Controller Class
Detect Tap on Calloutbubble in Mkannotationview
How to Detect an iOS App Installed or Upgraded
Full Resolution Screenshots for iPhone 6 and 6+
How to Make Uipageviewcontroller Reuse Controller Like Tableview Reuse Cell
"This App Is Not Allowed to Query for Scheme Cydia" iOS9 Error
Is -[Uitableview Reloaddata] Asynchronous or Synchronous
About Viewcontroller's "Viewdidload" and "Viewwillappear" Methods