Skip to content

Instantly share code, notes, and snippets.

@marcuswestin
Last active August 29, 2015 14:08
Show Gist options
  • Save marcuswestin/b9363a8d5bbb3839967d to your computer and use it in GitHub Desktop.
Save marcuswestin/b9363a8d5bbb3839967d to your computer and use it in GitHub Desktop.

· Create xcode Framework (MySDK) · Create xcode Project (MyDemo) · Create workspace · Add projects to workspace (Must close them first!)

· Create MySDK.h/.m in framework. · In SDK project Build Phases > Headers > Move MySDK.h from Project to Public.   Create new target in SDK project (Aggregate Target, e.g MySDK_ALL)   Under new target "Build Phases" select "Add Run Script" and copy the contents of the script below   Select Aggregate Target scheme, then build (cmd+b)

  Copy MySDK.framework into demo project   import <MySDK/MySDK.h>   Et voila!

	#!/bin/sh

	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}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build

	# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
	cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"

	# Step 3. Copy Swift modules (from iphonesimulator build) to the copied framework directory
	cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/Framework.swiftmodule/." "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/Framework.swiftmodule"

	# Step 4. 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 5. Convenience step to copy the framework to the project's directory
	cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"

	# Step 6. Convenience step to open the project's directory in Finder
	open "${PROJECT_DIR}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment