I\'m trying to make a dynamic framework for an iOS app. Thanks to the new version of Xcode (6) we can select a Cocoa Touch Framework when we create a new project and there i
Few additional points around the approach shared by vladof that are more applicable to swift based Frameworks
Try the following steps to create a workspace that contains a framework project and an app project.
Workspace:
Framework project:
App project:
Note that above example demonstrates how to build an app that runs in simulator. If you need to create universal static library that runs on both simulator and devices, then general steps are:
There are good references on the web about it, here for example.
Create universal binary for framework: navigate to framework Derived Data directory then /Build/Products, following command should help you create a universal binary in Products directory:
lipo -create -output "framework-test-01-universal" "Debug-iphonesimulator/framework-test-01.framework/framework-test-01" "Debug-iphoneos/framework-test-01.framework/framework-test-01"
Note that framework-test-01 is my framework project name.
I've changed someone's script a bit to support all Simulator's architectures:
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator VALID_ARCHS="x86_64 i386" BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# Step 2. Copy the framework structure to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
# Step 3. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
# Step 4. Convenience step to copy the framework to the project's directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"
# Step 5. Delete temporary build directory in the project's directory
rm -rf "${PROJECT_DIR}/build"
# Step 6. Convenience step to open the project's directory in Finder
open "${PROJECT_DIR}"
Sorry I've let this topic open for such a long time... Some of you has correctly answered to my question. When I wrote this question I didn't catch there were two slices in a complete (also called fat) framework (ready to use). One for the iOS devices and one for the simulator. When I discovered that I made a script using lipo command to fusion the two slices and got automatically a complete framework.
The way I did it is similar to vladof, but hopefully a little simpler. I made the framework a subproject of the app project.
Framework project
App project
For an Obj-C app
For a Swift app
By doing it this way, the app is dependent on the framework so if you make a change in the framework classes, you don't have to change targets to build the framework separately, it will just compile the framework first, then the app.
Wanted to add something to the lipo script answer provided by skywinder here. I followed the steps but still couldn't get my framework to run on simulator, only device. To fix that:
-I went into the debug-iphonesimulator version of the framework, and in Modules/[FrameworkName].swiftmodule, I copied all of the i386 and X86 files.
-I then went into the newly-created fat version of the framework, and navigated to that same folder. I pasted in the i386 and X86 files (to go with the ARM files already in there), and then added my fat framework to my project.
Voila, she works on simulator and real device! This is Xcode 10 / Swift 4.2 btw