Xcode
embedded binaries
linked frameworks
iOS development
app optimization

When should we use embedded binaries rather than Linked Frameworks in Xcode?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Xcode offers a robust environment for developing applications on Apple platforms, providing various options for managing dependencies and including external code. Two primary methods are utilizing "embedded binaries" and "Linked Frameworks and Libraries". Understanding the appropriate context for each is crucial in ensuring efficient app performance and maintainability. This article explores when to use "embedded binaries" versus "linked frameworks", providing technical insights, examples, and a comparison table.

Understanding the Terminology

Before diving into the specifics, let's clarify what "embedded binaries" and "linked frameworks" mean:

  • Embedded Binaries: These are binaries such as dynamic frameworks or libraries that are included directly into your app's bundle. When you package your application, the embedded binaries are included, allowing the app to access the code within these binaries at runtime.
  • Linked Frameworks and Libraries: When you link a framework, you are telling Xcode that the app will use the framework's resources. However, the framework itself isn't physically included in your app bundle unless specified as an embedded binary. Instead, at runtime, the app expects these frameworks to be available and will link to them dynamically.

When to Use Embedded Binaries

1. Dynamic Frameworks Requiring App Bundle Access

When a framework requires resources that are specific to its operation and must be included in the app bundle, it should be embedded. This includes frameworks with resources such as storyboards, asset catalogs, or any resource files bundled within the framework.

2. Distributing Standalone Functionality

Suppose you are distributing parts of your app functionality through dynamic frameworks or libraries that don't exist on the host operating system. These should be embedded in the app bundle since they won't be available by default.

3. Custom and Private Frameworks

For custom frameworks developed in-house or private frameworks not available on the App Store, embedding is essential. This ensures that the framework is available to the app at runtime.

4. Shared Frameworks for Extensions

In cases where you have several extensions or a main app using a framework, the framework should be embedded to ensure uniform access and functionality across these components.

5. Security and Versioning Concerns

By embedding, you circumvent potential issues related to versioning conflicts with frameworks installed on the device. This approach can also help protect proprietary code by bundling it within the app.

When to Use Linked Frameworks

1. Standard System Frameworks

System frameworks that are available across all Apple devices, such as `UIKit`, `Foundation`, or `CoreData`, should be linked but not embedded since they are built into the OS.

2. Third-party Frameworks Available through Package Managers

When using package managers like CocoaPods or Swift Package Manager, frameworks are usually linked. It allows Xcode to manage their versions, updating them across projects as needed.

3. Dynamic Libraries with Minimal Resource Needs

Some dynamic libraries or frameworks don't require bundling but are rather linked dynamically at runtime, provided they exist on the system or the deployment target guarantees their existence.

4. Performance Considerations

Considering cycling through frameworks at runtime, linked frameworks provide a slight edge in performance, as they aren't inflated into the app bundle, reducing app size and load times.

Example Scenario

Consider an app that uses a proprietary charting library developed in-house. Since it's proprietary and not available on devices, it should be embedded. For a secondary functionality that leverages a popular networking library managed through CocoaPods, the library should be linked as it is externally manageable.

Key Points Summary

Here is a table summarizing when to use embedded binaries versus linked frameworks:

Feature/RequirementEmbedded BinariesLinked Frameworks/Libraries
Requires App Bundle InclusionsYesNo
Provides Standalone FunctionalityYesNo
Custom Private FrameworksYesNo
Standard System FrameworksNoYes
Third-party Package ManagersNoYes
Reduces Versioning ConflictsYesNo
Security ControlsHighLow
Performance (app load time)Slightly SlowerFaster (due to reference only, not embedded)

Additional Considerations

  • App Size Implications: Embedding increases the size of the app due to the inclusion of the framework within the app bundle. This can affect download sizes and initial launch times.
  • Continuous Integration: When using CI/CD pipelines, managing embedded binaries can require additional configurations to ensure builds succeed correctly with all necessary dependencies.
  • Development and Testing: Testing with embedded binaries requires developers to continuously ensure compatibility with the latest OS versions and app updates.

By understanding these intricate differences, developers and teams can make informed decisions about when to use embedded binaries versus linked frameworks, optimizing their app's performance, maintainability, and security.


Course illustration
Course illustration

All Rights Reserved.