26

Up until iOS7, Apple did not support dynamic linking due to security concerns. Code reuse between developers usually relied on static libraries, which were built as part of the executable of the app.

Introducing extensions in iOS8 seems to change this a bit, because extensions are separate executables. Sharing code between an extension and its containing app is done via a framework. Apple is saying this in their release notes:

Frameworks for iOS. iOS developers can now create dynamic frameworks. Frameworks are a collection of code and resources to encapsulate functionality that is valuable across multiple projects. Frameworks work perfectly with extensions, sharing logic that can be used by both the main application, and the bundled extensions.

Emphasis is mine.

Source: https://developer.apple.com/library/content/documentation/Xcode/Conceptual/WhatsNewXcode-Archive/Articles/xcode_6_0.html#//apple_ref/doc/uid/TP40014509-SW14

Further, in the extension dev guide, they explain that you can share code between an extension and the containing app via a "embedded framework".

Source: https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW1

My question is - what is an embedded framework, how does it differ from a dynamic framework, and will we really see proper dynamic linking in iOS8? All the documentation I've read seems ambiguous about this.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Slavo
  • 15,255
  • 11
  • 47
  • 60
  • Weren't we allowed to use embedded frameworks or frameworks in general anyway??? Have multiple apps in the app store that use embedded framework and then just branding slapped on top in the actual app. Or have I just missunderstood what you were saying? – Popeye Aug 01 '14 at 13:07
  • Usage of frameworks was enabled, but they were all static, meaning that they were built as part of the executable. Now that we have extensions, if we keep doing the same, the app executable and extension executable would be duplicating the framework code (assuming both link the framework). This is weird to me, so I am asking if Apple changed and allowed us do link dynamically (i.e. link an out-of-executable framework at runtime). Also, they have the words "dynamic framework" in that document. – Slavo Aug 01 '14 at 13:13
  • OK I think I understand what you mean, I had to wrap it through the old brain a few times to understand but I think I got it but I don't think I have an answer for you sorry. – Popeye Aug 01 '14 at 13:29

3 Answers3

16

"Embedded" and "Dynamic" frameworks don't refer to the same aspect of frameworks. They are not the opposite of one another. First, let's define what's a framework: in Apple lingo, a framework refers to some compiled code + the public headers of said code.

  • Now a dynamic framework is a framework whose code was built as a dynamic library. It is the opposite of a "static" framework, where the code would be built as a static library. In case you're wondering, Wikipedia has a very nice explanation of what's the difference between a static and a dynamic library.

  • And finally, an embedded framework is a framework that is packaged within an app, as opposed to being installed system-wide, in "/System/Library/Frameworks" for example.

Ecco
  • 1,323
  • 1
  • 11
  • 15
  • 4
    Even though the wording may be different, isn't this the same concept? All static frameworks have to be linked with your application code. The result is a single executable, so you're saying all static frameworks are embedded frameworks. Then this doesn't answer my question. Are there non-embedded dynamically linked frameworks in iOS8? – Slavo Oct 17 '14 at 13:56
  • You can distribute a static framework apart from an app. Think "Google Analytics" for example. Are there non-embedded dynamically linked frameworks in iOS8?: Of course: all the system frameworks (Foundation, UIKit, etc...) – Ecco Oct 17 '14 at 14:28
0

An embedded framework is simply one that's included in the app bundle, rather than a global framework which is installed in system directory.

Droppy
  • 9,691
  • 1
  • 20
  • 27
-2

Dynamic Frameworks doesn't means dynamically linked framework. Apps still just work in a sandbox environment. It's not like your custom frameworks are going to be installed with the iOS. Each one of your apps that uses the common framework that you've developed is going to be copied inside every app's bundle.

You can see this for yourself. Go to your Xcode's Derived Data directory and inside the app's data, you'll find all the embedded frameworks copied.

The only new thing with creating Frameworks with iOS 8 compared to static libraries is that the public header files and assets gets bundled within the Framework. If you've been doing this sort of things with earlier versions of Xcode, you'll remember the pain with supplying public headers and then adding the search path within Xcode settings and for assets we had to pass in a separate bundle.

This only downside of using Frameworks that I see is that now we can't simply use lipo to generate a fat static library for all kind of architectures.

IMO Apple is using the word 'dynamic' to suggest 'independent'.

Watch WWDC2014 - Building Modern Frameworks for more details.

chunkyguy
  • 3,509
  • 1
  • 29
  • 34
  • Dynamic frameworks actually precisely means *dynamically* linked framework, in iOS/OS X world. Just build a sample iOS framework and do "file MyLib.framework/MyLib" and see how it's a Mach-O dynamically linked shared library. – Ecco Oct 16 '14 at 09:08
  • So you're saying that all the custom frameworks we write are going to be made available for everybody else dynamically? – chunkyguy Oct 16 '14 at 10:26
  • 5
    Nope, iOS won't allow that. The OS will not let you load a dynamic library from outside of your app's sandbox. System frameworks are inside the sandbox, but frameworks from other apps aren't. Frameworks were introduded in iOS 8 to let you share code between your main app and extensions. Both of those can load frameworks from inside of your app's container. Other apps cannot. – Ecco Oct 16 '14 at 11:25
  • OK @Ecco, I think I understand now. In theory those are dynamically linked, but the OS security mechanism (sandboxing) doesn't let you link any frameworks outside the sandbox. Could these still potentially be used on jailbroken devices? – Slavo Oct 17 '14 at 14:00