Cocoa touch framework embed other libraries - ios

They asked me to create a cocoatouch framework that bundles all off our 3th party frameworks. So that we can use that framework all over the company.
Now I think it's better when you make the application responsible for adding the dependencies that your framework need but this not possible here.
So I created a framework added some frameworks like PureLayout.framework, etc.. and added them to the linked frameworks and libraries.
It compiles and delivers a .framework but when I add that framework to the project and run it, then I get this error:
dyld: Library not loaded
Reason: image not found
So I think they are only linked against and not embedded in the framework.
How can I really embed them?

Related

How to build an iOS Framework with a dependency on another without creating an Umbrella Framework

I am trying to streamline my development by creating some re-usable Frameworks which incorporate features I commonly re-use in multiple projects.
However, having setup one of my Frameworks I have encountered a problem, the classes have a dependency on the Firebase framework. Having read the Apple docs it's not recommended to create an Umbrella Framework (one which embeds another) especially if you do not have ownership of the embedded Framework (which I do not).
So the question is:
How can I create a Framework project which allows me to build the Framework without including the dependencies which would create an Umbrella Framework. I presume this is what people like Firebase do because when you add their Framework there are others you have to add to your project as well. I can't quite see how you would configure a project to allow you to build the Framework without errors but not include the dependencies.
For reference I am using the latest Xcode and need to support iOS 8 and above.
Thanks in advance for any thoughts / suggestions on this
For the benefit of anyone who is struggling with the same issue, the answer is much simpler than I had anticipated.
The Frameworks are linked dynamically and simply adding a Framework to the project for your own framework will not cause it to be embedded in the output file and therefore not generate an Umbrella Framework. You don't actually need to do anything. Any Frameworks that are required by your own Framework can be included in your project so that you can compile your own Framework, and will also need to be included in any projects that utilise your Framework.

Use third party framework which is embedded in dynamic framework

As i understand the big change from ios dynamic framework and static is that static is linked statically to the code at link time (prior to launch) and dynamic is linked at launch/runtime
Now i have a test project:
My project have a dynamic framework linked to it - A.framework.
import A.framework
A.framework have a framework embedded inside of it - B.framework
In my main project i want to use classes from B.framework
Now i see that with a simple import statement in the main project:
import B.framework
It actually work and i can use code from inside of the B.framework which is embedded in linked A.framework
How can it be? is it something that is safe and reliable to use? How does the main project recognize the B.framework?
What about cases where the main project directly link the B.framework to the project? in this case i see many "duplicate symbol errors" at link time
Most importantly how can i build A.framework while not embedding B.framework inside of it, while off course using its classes and functions
Any clarifications will help :)
As you note, linking B.framework would lead to duplicate symbols. This is why A.framework should not embed B.framework. You must never embed a framework in another framework if there is any chance that the consuming application will care about the embedded framework (in practice, this means you really should just never do it).
A.framework was incorrectly packaged. If you packaged it, you should remove the embedded framework and link everything at the application layer. If someone else packaged it, you should open an issue with them to correct this error. This issue is not new to dynamic frameworks. It was equally a problem with static frameworks. The only appropriate time to link dependencies is at the application layer.
(There is an exception if you control the entire ecosystem (e.g. Apple). Then things like umbrella frameworks are acceptable. But you're not Apple.)
EDIT: It is ok to link, but not embed, a shared framework into another shared framework. The key is that the only copy of the shared framework needs to come from the top-level application. Since that final link step will happen at load, then you won't have duplicate symbols because there is only one copy of the shared framework. Just don't embed the sub-framework into yours.
For example:
Create project with framework target
Drag in GMA.framework to framework target (this will cause it to link but not embed)
Create App target
Have app link both GMA.framework and your test framework. This will work fine without collisions because there is only one GMA.framework, and it's only embedded in the app.

Using code from framework without linking it

I am building a cocoa touch framework and including in my code third party framework - "framework_X"
How can i use it in a way that "framework_X" will not be linked directly to my framework, instead it will require the consumer project which use my framework to link "framework_X" to his project in order for it to work.
In Android this is done easily, but in Xcode if i am not linking the "framework_X" in my framework the project won't build
You can load libraries at runtime. Here an example of loading zlib with dlopen():
https://github.com/nicklockwood/GZIP/blob/master/GZIP/GZIP.m

iOS8 framework library linking WITHOUT Pods

Imagine the following scenario;
I'm developing a cocoa touch framework that requires SomeLibrary (e.g. AFNetworking). My framework is going to be included into someone's project that might require SomeLibrary as well.
How do I accomplish this without running into these nasty duplicate warnings when I include AFNetworking into my framework directly (either via source code or Cocoapods)?
I've tried it with Cocoapods on both projects (my framework, and a test project that includes my framework), but that results in duplicate code warnings as well.
When I don't add AFNetworking into my framework development project, the compiler can't find the required files, which is why I can't build it. I've tried with including AFNetworking's source code directly into the main project, and using the pod, but in both cases the AFNetworking/AFNetworking.h import in the framework project fails.
How can I do this without making a pod out my framework (which isn't really an option)?
I've found this related answer, but I don't know what search path to set for the framework project in order to find a library of the master project;
https://stackoverflow.com/a/23123725/1069487
Any help would be highly appreciated!
You will have to build your framework linked against static library.
You build AFNetworking as a static library (that will give you a .a file as AFNetworking.a)
You build your framework that link against your static library. But be aware that the library won't be embedded in your framework (there is no way to include static library into framework on iOS). Your framework is able to use AFNetworking API because it is linked against it.
any project that use your framework and use AFNetworking methods of your framework need to link with the static library AFNetworking.a that you should provide as a standalone file beside your framework.
See iOS-Framework here for more details : https://github.com/jverkoey/iOS-Framework

Third-Party Static Frameworks within a XCode Framework Project

I have created a iOS Framework using the iOS-Universal-Framework:
https://github.com/kstenerud/iOS-Universal-Framework
When I use a static library, let's say libGoogleAnalytics.a I can build my framework let's say MyObjectiveCLib.framework and put everything into the main app. The static libraries will be properly linked into the app.
As soon as I try to add another Third-Party static framework, let's say WindowsAzureMessaging.framework to the framework project, I cannot build the app if I don't link this framework against the app too.
So I'm going to have the WindowsAzureMessaging.framework twice within the iOS app and within the app's core framework MyObjectiveCLib.framework
A solution that I have found is to build every imported framework as a static library (of course we are talking about static libraries in all cases, since it's all about static libs in iOS, hence in this case we are talking about a static framework).
Anyway I cannot do this for every framework when I do not have the source libraries for them.
So since iOS8 release I was able to compile and run the Embedded Frameworks:
Look at my post XCode 6 and Embedded Frameworks only supported in iOS8

Resources