98

When using external framework Xcode now has an Embedded Binaries as well as Linked Frameworks section.

enter image description here

When you download an external framework and Finder->drag it into Xcode, it will place the framework into the Linked Frameworks and Libraries section.

When you build a library with Carthage it recommends dragging into the Embedded Binaries section.

Both seem to be working in terms of linkage, as the API becomes available either way, further more when adding a framework into the Embedded Binaries section is it also automatically gets added into the Linked Frameworks and Libraries section.

So, who is right? Carthage or the rest of the internet? and why are there 2 options for including external resources into Xcode projects?

Maxim Veksler
  • 29,272
  • 38
  • 131
  • 151
  • And does it work when you test on the device? – trojanfoe Sep 03 '15 at 12:32
  • @trojanfoe yes it does. – Maxim Veksler Sep 03 '15 at 13:02
  • That doesn't make sense, unless it's either 1) in the embedded binaries section or 2) has a build step to copy the framework into the app bundle during the build. – trojanfoe Sep 03 '15 at 13:04
  • 2
    Carthage recommends dragging into "Embedded Binaries" only for OSX applications. For iOS, they recommend "Linked Frameworks and Libraries" only. – Damnum Jun 02 '16 at 10:13
  • Possible duplicate of [Link Binary with libraries VS Embed Frameworks](http://stackoverflow.com/questions/27015154/link-binary-with-libraries-vs-embed-frameworks) – Suhaib Feb 12 '17 at 03:36

5 Answers5

82
  1. Linking- We must link a framework if we use any API defined in it.

  2. Embedding - This process will ensure the added framework will be embedded within the App bundle, and potentially will help sharing code between the app, and any extension bundles. We embed only third party frameworks and not the ones provided by iOS as they are readily available in the device. If we are embedding, that means that, we will need to link to them too so that Xcode can compile and create the build. When the app runs in the device, then the embedded framework will be loaded into memory when needed.

Shripada
  • 6,296
  • 1
  • 30
  • 30
  • 1
    What do you mean with the "when needed" part? Does that mean that the embedded framework is loaded when it's needed during runtime? Also, when do you think the linking will happen for a dynamic framework? – bartosss Sep 01 '18 at 06:58
  • Is there a case we need to `embed` it and not `link` it? And vice versa? And why? – allenlinli Mar 08 '19 at 02:37
  • I think you only need to link frameworks whose API you use directly in the code, transitive dependencies which are not referenced in the application code should just be embedded if I'm correct. – Werner Altewischer Mar 13 '19 at 09:55
18

If you embed the binary it will be included into your product. If you only link a library or framework without embedding it, it will not be part of your product.

However, in iOS8 all 3rd party frameworks need to be "embedded". Even a framework that is shared between various programs needs to be "embedded" into every single one of those programs. In the case where it was installed on the device in a shared location, any other installation process using the same "embedded" code from the shared location can re-use that existing installation. This is specific to iOS8, it has not been possible before iOS8 and outside the iOS world this answer would not be accurate.

TMin
  • 2,280
  • 1
  • 25
  • 34
Basti
  • 246
  • 2
  • 9
  • 2
    "Embedding the binary will make it easier to install your product for the user in case they don't already have a working installation of that stuff on their machines" sounds like OSX, not iOS... if they don't have the library installed (i.e. it's non-standard) then the app simply won't load. – trojanfoe Sep 03 '15 at 12:44
  • it would not only not load, @trojanfoe, it would be rejected and you could not install it in the first place (unless you are the developer or use an Enterprise account ...) – dogsgod Sep 03 '15 at 12:47
  • Dynamically linked framework are possible since iOS 8 – Basti Sep 03 '15 at 12:47
  • When the user installs your app and if that app includes a dynamically linked framework, that framework can be searched for automatically. However, this is an additional point which may fail during the user's installation process, raising a link edit error which terminates the application. So I see no reason why the answer should only apply to OS X and not to iOS. Please be more specific if you see room for improvement concerning my answer. Or upvote that answer in order to make a fellow developer a full SO member, if you think the answer already is accurate ;) – Basti Sep 03 '15 at 13:15
  • It's the optional aspect to your answer that I object to. If the framework is 3rd-party then it must be part of the app bundle. Period. This is also largely true to OSX apps as well (certainly for apps distributed via the Mac App Store). – trojanfoe Sep 03 '15 at 13:37
  • Thanks, I edited the answer. I think it's a bit unfortunate that the answer shall relate to iOS8 only as visitors who are new to coding might be mis-lead concerning the underlying concepts. On the other hand I think you are absolutely right. And since the guy who was asking the question already has a lot of SO credits he might not want to read anything about the general concepts of linking frameworks and libraries anyway... – Basti Sep 03 '15 at 14:21
  • @Basti " in iOS8 all 3rd party frameworks need to be "embedded" why is that? – onmyway133 Jan 18 '16 at 04:27
  • You should mention you only need to embed a 3rd party framework if it's a shared library/framework, not a static one. See https://stackoverflow.com/a/58860158/3783833 – agirault Feb 05 '20 at 19:57
0

Linking more about Linker that works at compile time or load/run time. Linker copy a Library into a target binary. Since Framework is autonomous, the Linker, in this case, is responsible for find and link the Dynamic Framework inside the system loader path or to find and link inside a bundle.

Embedding is a process of copying the binary into the target binary. As a result it will be located inside.

Read more here

yoAlex5
  • 29,217
  • 8
  • 193
  • 205
0

Linking- We must link a framework if we use any API defined in it.

Embedding - This process will ensure the added framework will be embedded within the App bundle, and potentially will help sharing code between the app, and any extension bundles. We embed only third party frameworks and not the ones provided by iOS as they are readily available in the device. If we are embedding, that means that, we will need to link to them too so that Xcode can compile and create the build. When the app runs in the device, then the embedded framework will be loaded into memory when needed

.

M Mahmud Hasan
  • 1,303
  • 1
  • 13
  • 20
-3

To my understand, the embedded binary only includes dynamic framework that is available on iOS 8 and above, otherwise you can only link the framework that is static.

Lei Zhang
  • 634
  • 4
  • 6