Adding A Framework Target
Apps wishing to utilise frameworks to share code across different parts of their application, such as between an app and an app extension, need to start from the framework template appropriate for the app’s target platform. The framework target can be added to the same project as the app target, or it can be added to a separate Xcode project.
- Create a new Xcode target and select the framework template appropriate for your app’s target platform.
- Add all of the framework source files to the new target’s Compile Sources build phase.
- Set the visibility of header files needed by clients of the framework to Public.
- Add the public headers to the umbrella header file. If your framework is named
YourFramework, the umbrella header is named
- Follow the steps in Configuring Your Project to configure the new framework target as a dependency of the app target.
Configuring Your Project
Embedding a Framework
The steps to embed a framework vary, depending on the type of app you are building. The following sections describe how to embed the framework inside the built app for the different types of apps.
Embedding a Framework in an iMessage App
- Open the iMessage app’s Xcode project or workspace.
- Go to the Build Phases for the iMessage extension target.
- Add the framework to the Link Binaries With Libraries list. See Figure 3.
- Go to the Build Phases for the iMessage app target.
- Add a New Copy Files Phase by selecting the Add icon, highlighted in Figure 4. Set the Destination field to Frameworks, and add the framework to the list. Ensure Code Sign on Copy is checked.
Embedding a Framework in iOS, macOS, watchOS, and tvOS Apps
- Open the app’s Xcode project or workspace.
- Go to the app target’s General configuration page.
- Add the framework target to the Embedded Binaries section by clicking the Add icon, highlighted in Figure 5. Do not drag in the framework from Finder.
- Select your framework from the list of binaries that can be embedded.