Creating universal Cocoapods framework - ios

I have project with 10+ targets in Xcode. I am using cocoapods to provide me some frameworks.
But Pod projects starting to grow (many files)
It is possible somehow configure Pod file to create one universal configuration, which is imported to other projects? Something like abstract target?
I don't need for each target create new pod framework, because all my targets using same pods.
Thanks for suggestion.
Something like this:
platform :ios, '11.0'
custom config 'Pods-framewrks' do
use_frameworks!
pod 'Alamofire'
end
project = Xcodeproj::Project.open “./MyProject.xcodeproj"
project.targets.each do |t|
target t.name do
import framework Pods // ???
end
end

If you put pod 'Alamofire' outside of any specific target, then it will be included in all targets.
For example:
platform :ios, '11.0'
pod 'Alamofire'
target 'FirstTarget' do
end
target 'SecondTarget' do
pod 'SwifterSwift'
end

Related

Adding Framework in App Modules in iOS SDK

I am working on a project where I have added Firebase, Crashlytics etc using POD.
Now there is a requirement to create modules for each feature available in the app, so I created Modules for each Feature (Say Profile, Payment, Linking etc) & its working fine with main container app. Now My App looks like as below
Now I want to a use Framework(say Firebase) added Via POD in my module(Say Profile) but when I tried to import in a module I am getting
No such module 'Firebase'
Please suggest me how can add Framework added Via POD in any module.
Please also let me know If I have explained my question.
Below is my POD file
platform :ios, '8.0'
use_frameworks!
def mainPodPackage
pod 'Mapbox-iOS-SDK'
pod 'ZendeskSDK'
pod 'OneSignal'
pod 'Firebase/Core'
pod 'Firebase/Messaging'
pod 'FacebookSDK'
end
target 'Production' do
mainPodPackage
end
target 'PreProd' do
mainPodPackage
end
target 'Dev' do
mainPodPackage
end
This is how you can install pod for multiple project workspace, edit your podfile as so, test target should have same project as it's target:
use_frameworks!
workspace 'Workspace_name'
project 'PjA.xcodeproj'
project 'path_to_PjB/PjB.xcodeproj'
target 'PjA' do
project 'PjA.xcodeproj'
...
end
target 'PjB' do
project 'path_to_PjB/PjB.xcodeproj'
...
end

How to use Realm in both iOS and macOS projects of one workspace

I'm trying to figure out how to use Realm in both projects iOS and macOS of a single workspace.
At first try it fails to compile with more than 200 errors.
Workspace currently contains:
MyApp iOS project
MyAppMac macOS project
Pods project
Podfile:
workspace 'MyApp'
target 'MyApp' do
workspace 'MyApp'
xcodeproj 'MyApp.xcodeproj'
use_frameworks!
pod 'RealmSwift'
pod 'SVProgressHUD'
end
target 'MyAppMac' do
workspace 'MyApp'
xcodeproj 'MyAppMac.xcodeproj'
use_frameworks!
pod 'RealmSwift'
end
I just discovered that adding pod 'Realm' to MyAppMac target, works fine and produces no errors.
However, is this optimal?
I've seen some ways to reuse shared pods like RealmSwift but not sure how to do this given the configuration.

Targets within a target in a Podfile

I am trying to install the Google Mobile Ads SKD into my Xcode project. I installed Cocoapods and then initialized a Podfile into my project:
# Uncomment the next line to define a global platform for your project
platform :ios, '10.2'
target 'Cubical' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for Cubical
target 'CubicalTests' do
inherit! :search_paths
# Pods for testing
end
target 'CubicalUITests' do
inherit! :search_paths
# Pods for testing
end
end
However, I don't understand why there are targets within my main project (Cubical). I never really used CubicalTests or CubicalUITests, since I don't really need to test my UI or any snippet of code. I was thinking of removing these two folders.
My questions are,
1) Is there any drawback in removing the Tests and UITests folders from my Xcode project? And if I do, can I just simply delete those two targets from my Podfile?
2) Let's say I was going to keep those two targets. Would I have to add the pod to all three targets? Or do the two nested targets inherit any pods of target 'Cubical'
3) Do I need to add to Linked Frameworks the Google Mobile Ads SDK? Or is this already done by Cocoapods?
My final pod would look like this:
# Uncomment the next line to define a global platform for your project
platform :ios, '10.2'
target 'Cubical' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'Google-Mobile-Ads-SDK'
# Pods for Cubical
target 'CubicalTests' do
inherit! :search_paths
# Pods for testing
end
target 'CubicalUITests' do
inherit! :search_paths
# Pods for testing
end
end
Question 1:
There is no issue when you are removing Tests,CubicalUITests targets & folders, If you don't need to perform that kind of tests.
Question 2:
You can share pods with several targets like below,
def shared
pod 'Google-Mobile-Ads-SDK'
end
target 'Target1' do
shared
end
target 'Terget2' do
shared
end
Global pods for multiple targets
#Global Pod for all targets
pod 'Google-Mobile-Ads-SDK'
target 'target1' do
pod 'Fabric' #Pod for nested Target. i.e., Google-Mobile-Ads-SDK + Fabric
end
target 'target2' do
pod 'RadioButton'#Pod for nested Target. i.e., Google-Mobile-Ads-SDK + RadioButton
end
Pods for nested targets:
#Global Pod for all targets
pod 'Google-Mobile-Ads-SDK'
target 'target1' do
pod 'RadioButton' #Available for target1 and target2
target 'target2 copy' do
pod 'Fabric' #Available for target2 only
end
end
Question 3:
The linked frameworks are automatically done by cocoapods. See here you need to link the framework by using frameworks without cocoapods.

How to share parent(host) project pod with framework project swift?

i am developing Framework, i have added this framework project into host project. now i want to add cocoapods pod(framework) into parent(host) project. and share same pod into child(framework) project. or is there something i can add to Podfile and it will get share with child project.
SwiftProtoBuf framework, i want to use. and i don't wish to make umbrella framework.
can we share cocoapods pod between parent and child project
platform :ios, '8.0'
use_frameworks!
workspace 'ParentApp.xcworkspace'
abstract_target 'commonpods' do
pod 'SwiftProtobuf', git: 'https://github.com/apple/swift-protobuf.git', :tag => '0.9.24'
target 'ParentApp' do
project 'ParentApp.xcodeproj'
end
target 'ChildApp' do
project 'ChildFramework/ChildApp.xcodeproj'
end
end
or do i need to add pod to both project something like
platform :ios, '8.0'
use_frameworks!
target 'ParentApp' do
project 'ParentApp.xcodeproj'
pod 'SwiftProtobuf', git: 'https://github.com/apple/swift-protobuf.git', :tag => '0.9.24'
end
target 'ChildApp' do
project 'ChildFramework/ChildApp.xcodeproj'
pod 'SwiftProtobuf', git: 'https://github.com/apple/swift-protobuf.git', :tag => '0.9.24'
end
After little Struggle, i am able to solve it, it may help some-one in need.
Create Blank .xcworkspace , Xcode->File->New->Workspace
Open your .xcworkspace file in xcode, Add your Host(partent) project into .xcworkspace
add your framework(child) project in .xcworkspace.
and Podfile structure is like.
platform :ios, '8.0'
use_frameworks!
workspace 'MyWorkSpaceName.xcworkspace'
abstract_target 'CommonPods' do
pod 'SwiftProtobuf', git: 'https://github.com/apple/swift-protobuf.git', :tag => '0.9.24'
target 'MyHostAppProject' do
project 'MyHostAppProject/MyHostAppProject.xcodeproj'
end
target 'MyFrameworkProject' do
project 'MyFrameworkProject/MyFrameworkProject.xcodeproj'
end
end
make sure .xcworkspace is created and both your project is added into workspace, then only install pods to your project.

How to add one pod to multiple targets in Cocoapods?

Right now I need to add LiveSDK to multiple targets. Please see below:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '7.0'
target :CalDoKit do
pod 'LiveSDK'
end
pod 'Google-API-Client/Calendar'
pod 'LiveSDK'
As you can see the LiveSDK pod added twice. And I am getting warning from the console output when I run the application: One of the two will be used. Which one is undefined.
What's the correct way to add one pod to multiple targets?
New code:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '7.0'
link_with 'CalDo', 'CalDoKit'
pod 'LiveSDK'
target :CalDo do
pod 'SVProgressHUD'
end
But I am getting warning:
[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `TestKit` to `Pods/Target Support Files/Pods/Pods.debug.xcconfig` or include the `Pods/Target Support Files/Pods/Pods.debug.xcconfig` in your build configuration.
Solution 1:
Remove that 'target :xx do ... end' and add pod without defining targets. It will add the pod for all targets.
Solution 2:
Delete that podfile and run pod init command from terminal. this will make a new podfile with all the targets used in the project and then you can add pods separately for each target
Add this to the Podfile
target :AnotherTarget do
pod 'LiveSDK'
end
EDIT
This is the final Podfile source
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '7.0'
target :CalDoKit do
pod 'LiveSDK'
end
target :OtherTarget do
pod 'LiveSDK'
end
If you execute pod init console command on your project folder, it will create the Podfile with built in code.
See here: http://guides.cocoapods.org/syntax/podfile.html#target

Resources