Context
I am working on an existing Xcode project that utilizes SPM to manage several internal packages, among other things, that are used within an iOS application.
One of the internal packages contains Objective-C code that defines several extensions of objects and are imported throughout the application.
This package is no longer being actively developed, so I would like to embed it within the iOS application to reduce the compiler workload during a clean build.
Goal
To binarily link a static library that contain object extensions used throughout an existing application in order to reduce compile time.
What I have tried
First, I started by setting up and creating the external project to house the internal package
- Create a new Static Library Xcode project (we’ll call it ExtensionLibrary).
- Copy over the code from the main application to the new ExtensionLibrary project. This code is written in Objective-C and consists of several .h and .m files defining the extensions.
- Import all of the header files of the extensions into the ExtensionLibrary.h file
Example:
#import "SomeExtension.h - Add all of the .m files into the ExtensionLibrary’s targets compile sources under the build phases tab.
- Create a new aggregate target within the ExtensionLibrary.
- Add a run script that performs the following commands.
- Run xcodebuild on the ExtensionLibrary for the iphoneos SDK and iphonesimulator SDK
- Create a universal binary library from the completed builds using lipo
After this, I moved on to linking it to the main application using the following process:
- Deleted the internal package from the main application
- Added the universal binary library ExtensionLibrary.a file and ExtensionLibrary.h file into a new folder
- Added the path to the folder where the .a and .h files were copied to the Header Search Path flag
- Imported the copied over extension library header in the app delegates header file
Example:
#import <ExtensionLibrary.h> - Added the ExtensionLibary.a file to the iOS application’s Link Binary With Libraries Build Phase
Errors
There are two main errors that appear in the main application after doing this process.
- The imported header files for the extensions within the ExtensionLibrary’s header file can not be found in the iOS application.
- The extensions are not available to any of the UIKit objects.
Additional Notes
The main iOS application has the Other Linker flags -ObjC and -all_load set.
The main iOS applications app delegate is written in Objective-C.
The main iOS application is a combination of Swift and Objective-C code, both of which use the extensions defined in the ExtensionLibrary.
The cost to refactor existing code within the main iOS application using the extensions provided in the ExtensionLibrary would be very high, so the linked library needs to work with the existing application with as little changes as possible.
The ExtensionLibrary may undergo future development, so the process to re-link the library should be easily repeatable for future developers who have no experience with this process.
Examples of objects being extended: UIApplication, UIView, UIFont, NSDate, NSArray, and NSError
Question
The main question I have is how do I create and embed a static library of globally available Objective-C extensions into an existing iOS application written in Objective-C and Swift?







