iOS framework to wrap existing framework - ios

I'm trying to define a common framework in a project that provides an implementation-agnostic layer. For example, provide a protocol like Analytics and a set of methods/properties as its interface, and provide the implementation through a singleton object so different app targets would use the same implementation.
The issue is when importing the framework from within an app target, a compiler error occurs like so:
import Core // Missing required module 'Firebase'
What needs to be done?
In the Podfile, dependencies are installed only for the framework targets, not the app targets.

Dependencies should set to Core.podspec if you make framework manager by Cocoapods
Pod::Spec.new do |s|
s.name = 'Core'
s.dependency 'Firebase'
end

iOS framework to wrap existing framework,You have astray when you have this idea, One framework depends on the other. put the depends framework together with it when you use it, not contain or wrap. Cocoapods provides a simple way, create a new warehouse containing the two dependent frameworks, The idea of the first floor is right.

It turns out to be a pod installation configuration issue.
Changed the installation targets and the hierarchy, and things were solved.

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.

iOS CocoaPod that uses a separately distributed framework

My project involves creating a CocoaPod for public distribution that wraps functionality of a separate framework. The end-user project implements our wrapper and we deal with the complex system underneath. This means that our Pod references that separate framework but the end-user project does not.
I have had trouble working out how to automate the set up of the separate framework from within the podspec file. As it stands now, any time we run pod install we must add the framework to the Pod target for the methods to be correctly referenced. This may become a problem for other clients that use our Pod.
Is there a way to use the podspec settings to add a .framework file to the overall project?

podspec with dependency to another ios framework project

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

Static library with cocoapod dependency: define in Podspec s.dependency, in Podfile, or both?

I am converting a static library that we use in-house into a CocoaPod, so that our host applications can simply pull it in by referencing it in their Podfiles. This static library in turn depends upon a third-party Pod called HockeySDK.
In my static library's Podspec, I indicate the HockeySDK dependency as follows:
# MyStaticLib requires the latest HockeySDK framework:
s.dependency "HockeySDK", "3.6.4"
I also indicate the dependency in the Podfile that is in the root directory of my static library:
target "MyStaticLib" do
pod "HockeySDK", "3.6.4"
This seems to work fine - if I reference MyStaticLib in the Podfile of MyApp, it pulls in MyStaticLib and also magically pulls in the HockeySDK dependency, and all is good in the world.
What is the difference between these two seemingly redundant mechanisms for indicating the HockeySDK dependency? Why would I use one or not the other or both?
The first scenario is used to indicate that your library has a run-time (and also compile-time, because in cocoapods essentially all run-time things are also compile-time) dependency on HockeySDK.
The second scenario says your target depends on HockeySDK in order to build.
The difference is pretty subtle but is more obvious if you're not statically linking. Since you're linking statically, a compile-time and run-time dependency is the same thing (meaning the second scenario is the same as the first).
If you were linking dynamically against HockeySDK, then the host application needs to be made aware of this so it can provide the dependent library when linking your library. The way to do that is by propagating the dependency via the podspec.
In the podfile, you declare 1. a target and also 2. that you need the object file as well as the headers from HockeySDK in order to compile the target. This only impacts the building of your own library. People consuming your library use the spec not the Podfile.

ObjC: Statics are not consistent across multiple frameworks when contained in cocoapod

So my situation specifically uses the Objection dependency injection library. However, I believe this could be an issue for other libraries as well.
Platform
iOS 8.0 Xcode 6.1.1. Cocoapods 0.35. Objective-C.
Set up:
I have 4 projects. 3 universal frameworks and a test app (I'm creating an api). The test app does not utilize cocoapods (though some other app might).
All three of my frameworks need to use injection. I created a pod file that looks like
workspace 'workspace.xcworkspace'
platform :ios, '8.0'
xcodeproj 'path/to/proj/one'
xcodeproj 'path/to/proj/two'
xcodeproj 'path/to/proj/three'
target :Project1 do
pod 'Objection', '1.4'
end
target :Project2 do
pod 'Objection', '1.4'
end
target :Project3 do
pod 'Objection', '1.4'
pod 'SDWebImage', '~>3.7.1'
end
Problem
When I use this set up singletons don't work in Objection. However, they only don't work if they (the singleton class) is defined in project 1 and then I call [JSObjection createInjector]; in project 2 (the projects don't make a difference, it is that create is called in a different project to the definition).
Current theory
After battling with this for a while I believe it is due to the warning along the lines of:
Objection is defined in Project 1, Project 2 and Project 3.
Which one will be used undefined.
So when the class registers itself with the injection system (e.g through objection_register_singleton(ClassX)). It is using the JSObjection definition from its project, which might not be the one being used for a class that injects it (e.g. objection_requires_sel(#selector(myClassXObject))).
Question
I want to be able to use the iOS frameworks setup as, from what I understand, it is better overall than static libs. However, I also want to be able to use Cocoapods (and have any app, that uses my api, use Cocoapods).
How do I either a) share one definition across multiple frameworks or b) setup a framework as a Cocoapod (I've seen that this is being developed).
I would love to be able to keep the frameworks linked through the xcode workspace so when one is built the frameworks it depends on are also built. Though having said that, my api will probably become a Cocoapod at some point anyway.
Thanks in advance (and for reading to here)
Indigo

Resources