How to use the Framework with external dependency - ios

I'm having the framework which has the external dependency with Alamofire. If I try to use the framework in my project, it showing ld: framework not found Alamofire in framework
I had setup all things to consume the framework in project.
Added framework in Embedded binaries and Build copy phase file
Things which I have tried: Check here
I need to use my framework with external pod dependencies.
Note: I have searched a lot and tried many solutions but know work in my case.

You may use a dependency manager like Carthage or CocoaPods in order to manage external dependencies in your framework. Follow their instructions how to use a framework from within a framework. This is the easy part.
Enable CocoaPods respectively Carthage in your framework so that it can be imported as external dependency by other projects. For CocoaPods this is more elaborated and requires you to create and publish a Podspec. Note, that you can create a private Pod if you don't want to share your framework. You will find more resources in the web (CocoaPods) how to accomplish all this. For Carthage usually there's little to no extra effort. Host your framework in some repository (private or public).
In your application, follow the instructions from the dependency manager how to import dependencies for an app. You possibly need to explicitly add secondary dependencies for Carthage (i.e. Alamofire) much like you add other depenendcies. CocoaPods would do this for your app project automatically when you install the Pods.
Import your framework in your sources. Before you build, ensure your dependencies will be build. Again, look for the documentation of the dependency manager how you accomplish this.

Related

Do I still need CocoaPod installation?

I am new to XCode and Swift. Trying to create a simple project that uses MQTT protocol. For that, there is a Swift library CocoaMQTT and there are directions on how to integrate it in an XCode project:
Installation
To integrate CocoaMQTT into your Xcode project using CocoaPods,
you need to modify you Podfile like the followings:
use_frameworks!
target 'Example' do
pod 'CocoaMQTT' end
Then, run the following command:
$ pod install
At last, import "CocoaMQTT" to your project:
import CocoaMQTT
The directives above are not straight forward to me as for a newbie, and I followed another way by importing the CocoaMQTT package through the XCode main menu: File -> Add Packages. Once the package was downloaded, I saw that the package (and the other dependencies) were automatically added to my project in the file navigator:
Question: do I still need to do CocoaPad installation as described above, or importing the package as I did is the new and sufficient way to integrate the library into the project? The Podfile that is mentioned in the instructions cannot be modified in XCode.
[Swift package] is the new and sufficient way
Correct. The library is now installed in your project and there is no further work to do.
In general, Swift packages supersede Cocoapods. Wherever possible, if a library offers a Swift package installation, you'll probably want to use that rather than Cocoapods.
In this particular case, you should file an issue on the documentation. They have added Swift Package as an alternative way of installing this library but they have forgotten to add that information to the instructions in the Readme.

How to import Carthage framework directly to the project in iOS?

I want to use Carthage dependency manager in my project. Due to security reason I'm not able to install the library through brew/package. Instead I got the Carthage library and it's having two files CarthageKit.framework and carthage exec files.
I've added the framework in the project and given the path in Framework Search path but it's not working. Don't know how to proceed it further. Can you please help me out.
Thanks in Advance!

iOS : How to generate a .framework file from a GitHub project

There is a Swift project on GitHub that I want to include in my iOS app.
In my iOS app, I use Carthage. But the GitHub project is not compatible with Carthage (only with Cocoapods), so I need to include the .framework file in my project manually.
How can I generate the .framework file without Carthage?
Building the framework is not always the same across projects. That being said, there should be a target available when you open the project to make the framework build. It should look something like this.
After clicking run the framework is usually output to the products directory.
If this doesn't work for you with this project then maybe you could share a link to the github page for the project and I could provide more instruction.
Fork Project
Change scheme to shared in scheme management (more information on Carthage docs)
Add your fork to your Cartfile
You can stop here but I highly recommend do this after:
Update README with information about Carthage support
Make a pull request

Standalone framework

I'm working on a project where I created a SDK (cocoapods) with two dependencies - AFNetworking and Realm.
Here is my process:
I create cocoapods project (in this project code is visible)
I use cocoapods-package to build a framework (with mangled symbols).
I then copy this framework to another cocoapods project which will be distributed to the public.
User who wants to use this SDK then 'installs' this cocoapod. When he does this AFNetworking and Realm are installed alongside (because they are dependencies)
What I would like to do is somehow embed AFNetworking and Realm inside a framework. I know that framework will be bigger in size. Main reason for doing this is so that user is not obligated to use the same version of AFNetworking and Realm.
The CocoaPods Packager is taking care of what you want here automatically.
You can pull in third-party dependencies using CocoaPods. (CocoaPods Packager is even capable of mangling symbols to improve compatibility with any symbols that might appear in the integrating app.)
The packager builds open-source podspecs for you. This podspec needs to declare all sources, resources and dependencies. Please note that podspecs never lint nor build when not all of their dependencies are declared correctly.
But as the packager takes care of vendoring the dependencies by mangling their symbols, it allows you to create a big binary, where the dependencies were included from static libraries.
On base of that build product, you can have a modified version of your podspec. This should not declare the dependencies anymore when they are included and shouldn't need declare the source files or need to have them publicly available anywhere, but instead you declare the built binary as vendored library. This still needs to specify the header files and have them accessible, so that consumers of the podspec are able to interface the API of your library.
The CocoaPods Packager creates this variant of the podspec for you as well.

React Native using Cocoapods

Is it possible to use cocoapods when using React Native?
If so, How can I require in JavaScript the pods projects?
Thanks in advance!
Yes. It's possible. React Native project is pretty much normal iOS application (In terms of XCode required to build it and quite a lot of React Native internal code is well... Native Obj-C). Since React Native project is already run via xcworkspace, so it's perfectly possible to add Obj-C pods to the ReactNative project.
Since a lot of dependencies used by RN apps are pure javascript rather than Obj-C code, it's more than convenient to keep both dependency systems - Cocoapods (for Obj-C dependencies) and npm (for javascript). Pods are kept in "Pods" directory and npm under "node-modules" and they are not clashing with each other. And it's pretty convenient actually to have different types of dependencies run by different dependency management systems.
UPDATE: by default ReactNative project is .xcodeproj based, but it's easy to convert it to .xcodeworkspace.
I even tried to add React Native itself as Cocoapods dependency and it was sort of working (but some dependencies expected React in the "node-modules" dir so I abandoned it).

Resources