podspec with dependency to another ios framework project - ios

I had developed a swift farmework to share with other developers(Lets name it B). This framework is using another ios framework project that I created recently with objective-c (lets name it A).
Now, I want to share framework B with cocoa pod. I wondering how should I link these two project in the podspec file. Does I need to share both of them with pod? or is there any other solution that just share project B?

I was having same question when I was trying to create a swift framework that is using obj-c framework, but didn't find an excellent solution.
So I've made a dependency in podspec file and now my swift framework can be installed by a podfile and it works fine. When I call pod install/update it installs/updates my framework and a dependency framework
The dependency can be created by one line
spec.dependency 'SomeOtherPod'
Check this link https://guides.cocoapods.org/syntax/podspec.html
Also you can check my podspec
The only thing that I don't like is that I have one warning in my project now:
Multiple build commands for output file
..../Build/Products/Debug-iphonesimulator/NMSSH/NMSSH.framework/Headers/NMSSH.h
Still trying to find how to solve it
Hope this will help you

You have 2 options:
1. Distribute both pods and use spec.dependency in your podspec file (see Woof's answer)
2. Add A source files directly to B's source files

Related

How to build Swift framework with 3rd party SPM dependencies

I've built swift frameworks before, but I've never dealt with one that has 3rd party dependencies.
What I have right now is a Swift framework that has a dependency on several Swift packages. When I build it I see MyFramework.framework in the products folder as well as bunch of dependencies. I can make XCFramework out of it, but when integrating (embedding) it into another app I see an error that MyFramework is missing its dependencies (see image below).
What am I doing wrong or missing?
Creating a framework (or xcframework) that has embedded other frameworks is not supported for iOS(I believe this is answered here).
But there is an other way. You can statically link all the dependencies of your library, so in the final framework the binary will also contain the code of its dependencies.
If you are using CocoaPods and the name of the framework is aFramework you can do:
target 'aFramework' do
pod 'Alamofire', :linkage => :static
end
Then you can use the created aFramework.framework in a application target that does not have the Alamofire framework, since the code will be "embedded" in the aFramework's binary.

Swift package manager for project migrated from Swift 2

I have a Swift 2 project, now converted to Swift 3. I was using HTMLKit pod, but the problem is that HTMLKit is no more on CocoaPods, but on swift package manager.
How can I add Swift Package Manager support to my existing project?
People say add dependency to package.swift but I have no such file in my project. How can I create this file?
Repositories under Swift Package Manager have certain layout. At the root of the repo you have Package.swift that provides a manifest for the repository, its name, type, dependencies, etc. You add it manually, just like any other source file.
However, before you do that please go through the documentation on SPM. It could help you to understand some specifics (like where do the dependencies end up in your repo once you check them out, how to arrange your own code so that SPM will handle it correctly, which folders to create, etc).

Xcode: create Framework with pod dependecies

I create a framework that use AFNetworking (installed with pod).
I can import this framework on my project and I can use all classes/methods that I exposed, so project compile.
When I try to run project on simulator, I obtain this error:
dyld: Library not loaded: #rpath/AFNetworking.framework/AFNetworking
Referenced from:
/Users/.../Library/Developer/CoreSimulator/Devices/F56F98F0-2AE0-4C87-AC9A-6E3B449762D1/data/Containers/Bundle/Application/BFA5359F-8FCE-4402-8487-CD9C002CB673/MyProject.app/Frameworks/MyFramework.framework/MyFramework
Reason: image not found
I already included 'MyFramework' under:
Build phases -> Embed Frameworks
I suppose I missing something on building Frameworks, but I can find out what! I already seen this unanswered question.
Who can I use MyFramework without installing Pod on MyProject again?
It is really delayed, for this issue but I have got my project working. It might not be the best way but it works. I am putting it here for future reference.
I wanted to do it without using Pods in the main project. The reasoning is, we are bundling our SDK into a framework.
So essentially, the first step I took was to get the framework project bundling without using the workspace. I just dragged the Pods project into the framework project.
Then I added the frameworks the the pods project creates and add them to my framework. I set them to optional and code sign. You can see them in the picture of where I added them under the build phases.
Then add them to your main project. not the framework the normal way by adding the project and or the framework. Then add it to the Embedded binaries and Linked Frameworks.
If it helps anyone, the solution mentioned by #ArtyomDevyatov does work. The trick is that you have to add 's.dependency' in podspec file.

Cocoa Touch Framework Dependencies

I'm trying to create a Cocoa Touch Framework. To create a framework is not a problem, I used this tutorial and it is good.
I need to use third party libraries inside: like openssl, XLForm, AFNetworking. I know that it is not correct to include them in my framework, I need to create a dependencies, but I can't find how to do this.
Moreover is it possible to use pods in my framework and just make dependencies to these libs. So user which will include my framework to his project will need just install these pods.
It seems that I found solution.
Thanks to #Droppy and thanks to this question.
What I did: I just installed pods to my Framework project but used this use_frameworks! key.
Then I dragged my Framework to my Project and installed pods there, also with same key, otherwise (when pod wasn't installed in my Project) I was getting error like:
dyld: Library not loaded: #rpath/XLForm.framework/XLForm...
I used XLForm inside my Framework.

Combine Cocoapods and Carthage

I'm creating a Swift framework that is dependent on several other third party frameworks. Both these other frameworks support Carthage and Cocoapods.
Is there any way I can make my own framework support installing using both Carhage and Cocoapods? Or is just not achievable and should I just pick one?
You can definitely make your framework available with both CocoaPods and Carthage. This is the path that I would recommend to allow your users to use whatever solution they prefer. Also note that setting a framework up to work with Carthage also makes it much easier for users who want to use your library without either of these solutions.
On a high level, for CocoaPods you'll want to create a podspec that lists your dependencies there. This way CocoaPods will manage downloading and configuring them along with resolving them against other user dependencies. See more here.
For Carthage you'll want to configure your project with framework targets for the platforms you support and add your dependencies in your Cartfile. More on that here
Combining both is actually not difficult. With my framework I have started with CocoaPods template containing Example and Pod directories. In the example project I created a new Cocoa Touch Framework target, made sure this target is Shared (in Product - Schemes - Managed Schemes) and dragged content of my Pod/Classes directory to the project (with unchecked Copy items if needed and added Target Membership only to this newly created framework).
This should be enough, Carthage should find this shared scheme and use it. Just keep in mind you have to commit changes and create a new git tag before using your framework from Carthage.

Resources