Frameworks gives you much more flexibility than static libraries, they can contain resources. But each embedded framework added to project increases startup time as well. If you can ship your source files, Swift packages may be the right choice for you.
What are the differences between static and dynamic libraries? Static libraries, while reusable in multiple programs, are locked into a program at compile time. Dynamic, or shared libraries, on the other hand, exist as separate files outside of the executable file.
In this article, you will learn how To Create a Framework in Swift. A framework is a bundle which contains a library along with associated resources like image files, nib files, header files,etc. It helps you to reduce your work as it already contains some functions within it which you can directly use in your code.
Examples of static libraries (libraries which are statically linked) are, . a files in Linux and . lib files in Windows.
The biggest advantage a framework has over static libraries is that they act as a neat way of packaging up the compiled library binary and any related headers. They can be dropped into your project (just like the SDK's built-in frameworks like Foundation and UIKit) and they should just work (most of the time).
Most frameworks contain dynamic libraries; frameworks created in Xcode using the Mac Framework template will create a dynamic library. The iPhone does not support dynamic frameworks which is why it has become common for reusable libraries of iOS code to be distributed as static libraries instead.
Static libraries are fine, but they require a bit of extra work on the part of the user. You need to link your project to the library and you need to copy the header files into your project or reference them somewhere by setting the appropriate header search paths in your build settings.
So: in summary, my opinion is that the best way of distributing your library is as a framework. To create a "static" framework for iOS, you can essentially take a normal framework and replace the binary with your compiled static library. This is how I distribute one of my libraries, Resty and is how I intend to distribute my libraries in the future.
You may want to look at the supplied Rakefile in that project (in case you aren't aware, Rake is Ruby's equivalent of Make). I have a handful of tasks for compiling my project (using xcodebuild
) and packaging them as a static framework for iOS. You should find this useful.
Alternatively, you may wish to use these Xcode 4 templates for creating an iOS framework.
Update 9 Dec 2013: this is a popular answer so I thought I'd edit to say that my first choice for library distribution has changed. My first choice for any third party library as either a consumer or producer is CocoaPods. I distribute my libraries using CocoaPods and offer a precompiled static library with headers as a fallback option.
basically, frameworks ARE libraries and provide a handy mechanism for working with them. If you look "inside" a framework, it's just a directory containing a static library and header files (in some folder structure with metadata).
If you want to create your own framework, you have to create a "static library" and pack it in a specific way. see this question
In general, framworks on platforms are used for reusable behaviour where you add your own code "into an existing framework". if you want to have some specific functionality, you may want to use a library (e.g. three20) and pack it into your app distributable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With