Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Static vs Dynamic frameworks clarifications

People also ask

What is difference between static and dynamic framework iOS?

statically linked modules are fastest to load (loading non-system dynamic frameworks is pretty expensive while system frameworks are optimized). When using static linking, all the symbols are within the same module, so the app start is fast. dynamically linked modules are slower to load, especially on iOS.

How do I know if my framework is static or dynamic?

If you are looking at a binary library / framework (perhaps it's precompiled by a 3rd party) and want to know if it's a static or dynamic binary, just use file command with the path to the binary file. Example (static framework) - static binaries are usually marked with ar archive or similar.

What is difference between static and dynamic in Swift?

To start things off, Static Dispatch is supported by both value types and reference types. However, Dynamic Dispatch is supported only by reference types(i.e. Class). The reason for this is that, for dynamism, or dynamic dispatch, in short, we need inheritance and our value types do not support inheritance.

Can we create dynamic library in iOS?

At the time this question was asked, Dynamic libraries were not supported by iOS and will result in your app getting rejected. Only static libraries are allowed.


Before iOS8, Xcode only allowed the option of creating static libraries for iOS. The common problem with that was we had to ship the binary and headers separately.

Later, some developers came with the idea of creating 'static frameworks'. [the .framework is just a folder with symbolic links to the lib and the headers]. One such example is https://github.com/jverkoey/iOS-Framework

This option will work for iOS 7 or 8 or before that. Because they are just static libraries with the convenience of bundling the headers files along.

As for your questions of the resources, we would need to bundle them in '.bundle'.. For shipping them i am not sure if we can enclose them in the .framework folder.. In the past i used to ship my libs as a static framework and bundle...

However the above option will not work for you if you use Swift. Xcode does not support building static libraries that include swift code.

You must go with Dynamic frameworks if there is swift usage. In theory, Dynamic frameworks work in iOS7.. But, i think iTunes Connect will reject if the app is targeting iOS7 and uses Dynamic frameworks :-).

Hope this helps


With Xcode 9 onwards you can create static frameworks for Swift as well. This is possible due to ABI source compatibility. All you need to do is just change the Mach-O type under build settings of the framework target. This technique is also applicable to Hybrid Frameworks(frameworks with Swift and Objective-C code).


Static vs Dynamic linking

static or dynamic in name usually points into a Linking[About] type

Frameworks can be static or dynamic[Check static or dynamic]

You can change the format of library that will have an impact on a Linker by changing Framework target -> Build Settings -> Mach-O Type[About] to Static Library or Dynamic Library. By default Xcode has Dynamic Library value.

Depends on this setting different types of binary will be generated

After you successfully configure a consumer[Link vs Embed]

Static Linker ld: at compile time will include all code from the static library into the executable object file.

Dynamic Linker dyld: at load/run time will try to find the embedded framework using @rpath[About] and link it

[Vocabulary]


I don't have all the answers but I'll try to address some of your questions here.

  • You will get a warning for using these frameworks in iOS 7, however that's all it is, a warning. See this answer.

  • You can include other resources like CoreData however you'll need to create them in code manually. Here's a tutorial showing how to create a core data model.

  • You have to code sign dynamic libraries for iOS.

  • You need to make sure your framework supports both simulator and device architectures if you're planning to distribute it.


Swift does not work in static lib. If you have to use dynamic framework, you have to set min iOS to 8.0 because AppStore reject ios 7 with dynamic framework