How to add XCFramework to Xcode project

XCFramework is a new code distribution format introduced by Apple in Xcode 11. The new XCFramework bundle type (similar to framework bundle) now allows to support multiple architectures, platforms and simulator in one package. As XCFrameworks are gaining in popularity, iOS developers will need to know how to use them in their projects. This tutorial covers the steps needed to add and integrate an existing XCFramework into your Xcode project.

First of all, double check if your Xcode project contains a “Frameworks” folder in project navigator. If it doesn’t, just like in the screenshot below, then we’ll have to create one. The Frameworks folder is not added by default in latest Xcode and it’s a good practice to keep your frameworks there.

Project navigator without Frameworks folder

Create Frameworks folder

Right click on your project in the project navigator (top-most entry) , and select “New Group”. Name the new group Frameworks.

Create new group in Xcode
Create new group in Xcode
Create new Frameworks group in Xcode
Create new Frameworks group in Xcode

Add XCFramework to Frameworks folder

There are two ways to add an XCFramework to the Frameworks folder. 

Drag and drop it from Finder into the Frameworks folder. Make sure that the destination of drag is just under the Frameworks folder:

Drag and drop XCFramework to Xcode project
Drag and drop XCFramework to Xcode project

Then, make sure the following options are selected for adding files. Both “Copy items if needed” and “Create groups” should be checked and selected. Click Finish.

Copy items if needed and Create groups
Copy items if needed and Create groups

The result should look like this:

New XCFramework added to Frameworks folder
New XCFramework added to Frameworks folder

Alternatively, with the Frameworks folder selected, click on File -> Add Files to “Your Project”…

Add Files to... method
Add Files to… method

Find the XCFramework in the file navigator, select it, make sure “Copy items if needed” and “Create groups” are selected and click Add:

Add XCFramework
Add XCFramework

Embed XCFramework in project’s target

In order to make sure that the framework will get copied to your app’s binary, follow these steps:

  1. Navigate to your project settings by clicking on it in the project navigator. 
  2. Make sure that your target is selected and General tab is open.
  3. Select “Embed & Sign” for your newly added XCFramework
Embed and Sign XCFramework
Embed and Sign XCFramework

Link XCFramework with your project

Navigate to the Build Phases tab, disclose the “Link Binary With Libraries” list and make sure your framework is included in the list. It should already be included by default after following the steps above, however in case it’s not – click on the + button and add it.

Link Binary With Library
Link Binary With Library

The XCFramework is now fully added and integrated with your Xcode project.

Take a look at Apple’s video from WWDC introducing XCFrameworks.

Related tutorials: