Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS Static Framework with resources inside

Tags:

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?

like image 636
Andrei Stanescu Avatar asked Aug 29 '12 14:08

Andrei Stanescu


People also ask

What is difference between static and dynamic framework?

Static and Dynamic Frameworks:Static frameworks contain a static library packaged with its resources. Dynamic frameworks contain the static/dynamic library with its resources. In addition to that, dynamic frameworks may conveniently include different versions of the same dynamic library in the same framework.

What is difference between static library and framework in iOS?

Frameworks are structured directories containing code, sub-directories, shared libraries, and other support files. Whereas libraries only has executable code. Assets cannot be carried along with a library. In contrast with Frameworks that we can put everything into a single package.

What is dynamic framework iOS?

A dynamic framework is a bundle of code loaded into an executable at runtime, instead of at compile time. Examples in iOS include UIKit and the Foundation frameworks. Frameworks such as these contain a dynamic library and optionally assets, such as images.

Does Swift support static libraries?

As mentioned, Apple does allow Swift in static libraries as of Xcode 9 Beta 4.


1 Answers

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.

like image 184
Ryan Poolos Avatar answered Sep 20 '22 00:09

Ryan Poolos