kstenerud/iOS-Universal-Framework — Issue #28: Bundled Framework
Author: computerpunc
Created: 2011-10-11 11:18:04+00:00
State: open

The title is more of a propose solution to 2 issues I've found when using real frameworks:
1. CoreData momd issue - as mentioned in the troubleshooting, when using the framework xcode retains the contents of the momd directory for core-data but flattens its contents to the root app directory, therefore core-data models cannot be accessed via momd extension but directly using the mom extension. Unfortunately, this imposes problems when using automatic migration by core data and can cause collision with other resources.
2. Distribution issue - using the current creation method for a universal embedded framework, xcode isn't updated when the framework has new resources. E.g., initial version of the framework had a single resource image.png. I would send the myframework.embeddedframework to my clients and they would add it to xcode. If the second version of the framework had another resouce, image2.png, upon receiving the new version, the client would replace on the HD, the old version with the new one, but xcode would not detect the new resouce. The client would have to remove the old version and add the new version in order for xcode to detect changes.

I would like to propose a solution to the above issues: provide a similar solution as provided in myframework.embeddedframework, but instead of having a myframework.embeddedframework/Resources dir with links to resources in myframework.embeddedframework/myframework.framework/... . Have a real resources in a dir that ends with .bundle.

To see this in action just add the following before the last section in the xcode script:
# Build embedded framework with bundle structure

echo "Build Embedded Framework with Bundle"

echo rm -Rf "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.bundledframework"
rm -Rf "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.bundledframework"
echo mkdir "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.bundledframework"
mkdir "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.bundledframework"
echo cp -a "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.bundledframework/"
cp -a "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.bundledframework/"
echo mkdir "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.bundledframework/${PRODUCT_NAME}.bundle"
mkdir "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.bundledframework/${PRODUCT_NAME}.bundle"
echo mv "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.bundledframework/${PRODUCT_NAME}.bundledframework/Versions/A/Resources/"* "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.bundledframework/${PRODUCT_NAME}.bundle"
mv "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.bundledframework/${PRODUCT_NAME}.framework/Versions/A/Resources/"* "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.bundledframework/${PRODUCT_NAME}.bundle"

# Replace other platform's framework with a copy of this one (so that both have the same universal binary)
--------------------------

In order to access the bundle in the iOS app you can use the following obj-c code:
NSString* bundlePath=[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"myframework.bundle"];
NSBundle* bundle=[[NSBundle alloc] initWithPath:bundlePath];

The above bundle will also be visible when calling: [NSBundle allBundles]

I hope this helps and if appropriate I would be happy to see this get into a release of iOS-Universal-Framework.

Punc.