Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding a framework within a framework (iOS 8+)

iOS applications built with Xcode 6 or higher allow embedding dynamic iOS frameworks within them. I am building a shared framework and would like to embed a sub-framework. How can I accomplish this?

Note: This is possible and is being used in production (for e.g., with Swift frameworks in CocoaPods).

like image 252
Vatsal Manot Avatar asked Jan 09 '15 19:01

Vatsal Manot


People also ask

How do I embed a framework?

Embedding a Framework in iOS, macOS, watchOS, and tvOS AppsOpen the app's Xcode project or workspace. Go to the app target's General configuration page. Add the framework target to the Embedded Binaries section by clicking the Add icon, highlighted in Figure 5. Do not drag in the framework from Finder.

How do I add embed frames to build phase?

You can create it on Build Phases tab! Just click in the "+" icon and select "New Copy Files Phase". After that, rename the item created to "Embed Frameworks" and set the "Destination" field to "Frameworks".


2 Answers

Found the answer. Here's how it's done:

  • Navigate to Target > Build Phases
  • Click the small "+" icon and select "New Run Script Build Phase"
  • Paste the following:

    cd $BUILT_PRODUCTS_DIR
    
    mkdir $PROJECT_NAME.framework/Frameworks &>/dev/null
    
    for framework in *.framework; do
        if [ $framework != $PROJECT_NAME.framework ]; then
            cp -r $framework $PROJECT_NAME.framework/Frameworks/ &>/dev/null
        fi
    done
    
like image 69
Vatsal Manot Avatar answered Oct 09 '22 12:10

Vatsal Manot


@Vatsal Manot's answer was very helpful for me. I modified it a bit and also had a need to sign the copied embedded framework. My script is below.

cd $BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/Frameworks/Custom.framework/Frameworks
for framework in *.framework; do
    mv $framework $BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/Frameworks/
    /usr/bin/codesign --force --sign "iPhone Developer" --preserve-metadata=identifier,entitlements --timestamp=none $BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/Frameworks/$framework
done
like image 34
Justin Domnitz Avatar answered Oct 09 '22 14:10

Justin Domnitz