Pants

A Poem About A Girl Pants. “Pants” is published by Cheryl Amyx.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How to build and use an XCFramework

XCFramework were introduced on wwdc 2019. They allow us to package different architectures of the same module into one entity.

On iOS, frameworks (dynamic or static) and libraries (static only) are two types of module that can be linked to another module, either in a compiled state or not.

Building an XCFramework is a two step process. First the framework or library needs to be compiled from source code. Xcode calls this product an archive. Then the archive is packaged into an XCFramework.

This article will show you how to proceed with both steps.

There are two main reasons for picking an archive (a compiled state of code) over source code.

The most obvious one is when you have no other choice. The framework or library might be from a vendor that only shares the compiled version of their code.

The second reason is to improve compile time. Even though Xcode gets smarter with the years, linking against a non compiled framework or library will increase your app compile time. If your project includes a framework or library that doesn’t change very often, it makes sense to consider compiling it and linking against its archive.

iPhone and Simulators run apps on different architectures. When Xcode builds an archive, it builds it for a specific architecture. Therefore if you want to create an XCFramework to run on both iPhone and Simulators, you will need to create two versions of the archive. Here’s the command line for archiving a framework with the iPhone sdk:

Building an archive for a library is quite similar to the process of archiving a framework. Except if you want to make it available to Swift. Whereas the default option for a framework is to define a module, it is not the case for a library.

Packaging a library into a module requires editing two build settings and adding a build phase:

After completing these preliminary steps, run the following command line for archiving a library with the iPhone sdk:

Or why is an archive not enough.

As mentioned above, Xcode builds an archive for a specific architecture. Therefore an archive could be run on the iPhone or on the simulator but not on both.

One solution is to combine different archives, each supporting a targeted architecture, into one package and let Xcode pick the correct archive at compile time.

Before XCFramework was introduced, developers packaged multiple archives into a so called Fat Framework. This enabled developers to ship only one package, supporting different architectures, but it also meant that it was upon the package users to add a build phase to strip the Fat Framework from not compatible archives.

Apple introduced XCFramework in 2019. XCFramework packages different archives into one xcframework product. On top of that, XCFramework format is supported by Xcode, removing the need to manually strip out not compatible archives during a build phase. Xcode takes care of it automatically.

It takes as input all your targeted architectures archives. If you have archived a library instead of a framework, simply change -framework with -library .

Drag and drop your .xcframework into the Frameworks, Libraries, and Embedded Content section of your target’s General tab.

Now is time to tell Xcode where to look for the module.

If your XCFramework includes a framework, edit the Framework Search Paths setting.

If your XCFramework includes a library, edit the Header Search Paths and Library Search Paths . If you link against a library that is not part of the same repo, you will need to copy over the public header files as well (in addition of the XCFramework of course!).

That’s it, you can now call your framework or library from another module. I hope that after reading this tutorial, you have acquired a better understanding of why you should consider using XCFramework and how to build them.

Add a comment

Related posts:

What is tf.data.Dataset? Part 1.

They always say that the simplest way of using tf.data.Dataset is the from_tensor_slices method. So give it a try. Suppose that I have a list of image file names and the variable name of that list is…

How to Save Without Compromising Lifestyle

It is the beginning of March. You are reviewing your bank statements and sadden by your leftover balances after your housing payment. Your long-awaited tax return had all gone to your credit card…

CHINA AND UAE CAN INJECT STRONGER IMPETUS INTO COOPERATION

The first China-Arab States Summit and the China-Gulf Cooperation Council (GCC) Summit which ushered in a new chapter in Chinese-Arab relations drew worldwide attention ever since they were announced…