I'm trying to build a framework that implements a REST API which I want to reuse and share. To handle the network access, I want to use Alamofire inside this API framework. Everything works so far except that my test app, which actually uses my API framework, won't build because Alamofire is missing.
In the app's target I can set "Embedded Binaries" to include my API Framework. If I also include Alamofire there, it works.
Now I wonder if there is a way to put the Alamofire framework into my API framework so that the app only has to include one framework. The API framework's target->general settings don't have the section "Embedded Binaries". But maybe this can be done in another way. Or is this not a good approach at all?
Thanks for your help!
--- UPDATE ---
Of course it is possible to add the source files of the Alamofire framework in my API framework. This way my app only has to import the API framework. But I still wonder if it's possible to include the Alamofire framework in my API framework.
Half a year later I learned that this is simply not meant to work this way in Xcode with iOS frameworks. If a framework depends on other 3rd party frameworks, you need to import those frameworks into your own target. I'm using Xcode 8 beta 3 and nothing changed so far and probably won't in the future.
I think the reason is simple: If the above would be possible, you could end up having one framework included several times in your project, because some of your frameworks include other frameworks include other frameworks include other frameworks include other frameworks include other frameworks...
I think you get the point :P
Related
We created a IOS framework which is distributed to various people. But now we came across an interesting problem. We use protobuf in our framework and one of our clients started using Expo Kit which also recently included protobuf and now our client gets a crash with our framework:
Class Foo is implemented in both ... One of the two will be used. Which one is undefined.
We can't use the Cocoapods Protobuf-ios because it is outdated.
My only option that I can think of is to build the framework without our protobuf files included for this client. So our framework will then use their Expo Kit profobuf files. How do I go about doing this in Xcode or is there an alternative solution.
Edit:
What I want to achieve but just can't seem to get it right. I want to distribute my Framework without my Protobuf.a file. Protobuf.a must be a dependancy on the client apps.
Have you considered moving to another, more maintained, Protobuf framework like the one from Apple (bonus points for being made for Swift).
https://github.com/apple/swift-protobuf
Hope it helps ;-)
You need to have a dynamic link to the package and avoid embedding 3rd party binaries in your framework unless neccessary.
Checkout these articles, hope they help you:
https://theswiftdev.com/2018/01/25/deep-dive-into-swift-frameworks/
https://www.bignerdranch.com/blog/it-looks-like-you-are-trying-to-use-a-framework/
Also this is interesting one:
When should we use "embedded binaries" rather than "Linked Frameworks" in Xcode?
You don't need to link Protobuf in you client application, if it is already embedding/linking your framework which contains Protobuf.
In you client application, you can provide the path of the Protobuf embedded inside framework. You just need to modify the Framework Search Path for client application and provide the path to protobuf embedded inside the framework.
I'm about to create a cocoaPod for a small iOS Framework for our customer. I have 2 questions about it.
1) I'm depending on another framework that is also available via cocoaPod. Could it happen that the original author removes the lib and therefor could kill my framework as well or is this secured?
2) I'm using Swift as the language of choice? Let's say one is importing an Obj-C Pod into a Swift project, he needs a bridging header. With the other way around, using a swift cocoapod with obj-c, does the user need to do anything to make this run?
Thanks
Yes, and hopefully the dependent framework doesn't remove his framework (its very rare they do it)
The bridging header is fine unless you use advanced generics (inheritance of a base generic class) as methods might not be available while converting to Objective-C.
I am developing an iOS App and a CocoaTouchFramework. The iOS App depends on the framework. My goal is to use a 3rd party Framework (in this case AlamoFire) inside my CocoaTouchFramework. According to this Stack Overflow link it is discouraged to have a Framework embed another framework. The way I understand it is that the consuming iOS App (the app which depends on the framework) needs to provide the 3rd party dependency and that my framework can reference that dependency. I don't know how to set this up in Xcode however. Here is what I have currently set up in Xcode:
AlamoFireApp is the actual App and AlamoFramework is my own Framework that will use AlamoFire to perform various network requests. I embedded the AlamoFire dependency into the App. How can I use AlamoFire in the Framework now? I've tried linking to AlamoFire from within the Framework (Adding Alamofire.framework) in the Link Binary With Libraries section) but I always get the No such module 'AlamoFire' error when I try to import AlamoFire in my Framework's classes.
Any help is appreciated.
#cbbcloud you can make your own cocoa pods using alamo fire. All you have to do is add them as dependency in pod spec. And then you can import the use the framework to build your framework.
Pod::Spec.new do |s|
s.name = 'YourFrameworkName'
//other info
s.dependency 'Alamofire'
end
If you are new to cocoapods , follow this link
https://guides.cocoapods.org/making/index.html
Ok I've found a way to do it. I was able to solve the problem by dragging the AlamoFire.Framework into my framework (in this case, AlamoFramework) in Xcode. The important part that makes this work is to check the 'Copy items if needed' checkbox.
After checking this, the compiler can resolve the Alamofire module and there are also no linker issues. However this approach seems to contradict the recommendation of Rob Napier in his answer to this question that states:
The only appropriate time to link dependencies is at the application layer.
I haven't done full-time iOS development for very long so if anyone has any input they can give to clear up this issue, that would be great. But my problem has been fixed for now so I can continue with development.
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.
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