IOS Static Framework with resources inside

2019-01-14 03:06发布

I'm trying to create a framework that keeps some common code I use around in my projects. I found online tutorials and managed to create a framework but I still have one problem related to resources (xibs, images, etc).

Let's say I have a MainViewController.xib which has a UIImageView using a test.png. All these are in my framework package.

When I use the framework in another project, I add it to the "Copy Bundle Resources" build phase. The problem is that the xib is only accessible using a path like dummy.framework/Resources/MainViewController.xib and the UIImageView inside can't load test.png.

It seems that the UIImageView will try to load the png from the root of the bundle, and not from the relative folder where the xib is also stored.

Has anybody managed to create a framework with code and resources and use it in another project?

7条回答
We Are One
2楼-- · 2019-01-14 03:33

I know this is an old thread, but to keep new people from making the same mistakes here is a note:

As of Xcode 6 and iOS8, Apple has a fully supported first party Dynamic Framework solution built in. For more information look here: https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_6_0.html#//apple_ref/doc/uid/TP40014509-SW14

But the short of it is, create a new project and choose the Cocoa Touch Framework template.

查看更多
登录 后发表回答