Started with an Objective-C and Swift mixed project...
Gradually I have converted all of the code over to Swift. Quite happy about that.
I've now turned my attention to all Cocoapod dependencies, and all the obvious ones have been either removed or swapped for Swift equivalents...
However, I am using Google Firebase Cocoapods (Objective-C) and cannot find a Swift alternative for it.
(I'm using Firebase for app analytics and help with push notifications)
Am I missing a trick here? Is there a good alternative for Firebase that is 100% Swift?
I know some may suggest I just keep Firebase in Obj-C, but my thinking is if I can 100% convert my project over to Swift I will be future-proofing it for a good few years.
Firebase doesn’t have a pure Swift SDK. I don’t think Google cares enough about iOS dependancies.
Also, technically if you’re looking to change proof iOS code, ObjC is “better” because unlike Swift it has no versioning.
But! I can’t recommend anyone to write a project in ObjC just because it might require less code maintenance.
I had the same problems when working in iOS 14 with Firebase pods. I ended up figuring out that the issue was only coming from the general 'Firebase' pod.
Basically, DON'T use:
pod 'Firebase'
And use the specific pods instead:
pod 'Firebase/Auth'
pod 'FirebaseCore'
pod 'Firebase/Firestore'
pod 'FirebaseFirestoreSwift'
pod 'Firebase/Storage'
pod 'Firebase/Analytics'
pod 'Firebase/DynamicLinks'
When you import frameworks to a file, import the specific pod. (ie. "import FirebaseCore" and not "import Firebase"). I would assume Google will eventually update the general pod to be compatible.
Related
In my project I've around 20-30 PODS and all of them are in OBJECTIVE-C.
In some of the pods I've changed some pieces of code due to requirement.
Now I want to add a pod which is only written in swift. Is it possible to use swift for only that specific pod ? I don't want to use "use_framework" as it will force all other pods to use static frameworks.
Currently use_framework! is either all or none. There is currently an open issue to change that.
Swift static library support will be added in CocoaPods 1.5.0 so that is likely to be the soonest route to a solution for you, but still a ways off.
With the release of cocoapods 1.5.0. Not it's possible to use only a single swift pods. From official docs
you can add use_modular_headers! to enable the stricter search paths and
module map generation for all of your pods,
or you can add :modular_headers => true to a single pod declaration
to enable for only that pod.
By this we can improve store submission time. Here is the official doc page Cocoapods 1.5.0.
There is so many things written about it but still I am unable to figure it out.
So here what I am doing:
I have create a Cocoapod Test Framework with code borrowed from some tutorial here and there. Repo
Podfile
platform :ios, '9.0'
target 'CocoaPodTestFramework' do
use_frameworks!
pod 'Alamofire'
pod 'SwiftyJSON'
end
In the framework I needed a http call so I used Alamofire and SwitfyJSON pods in my framework workspace. After successful buidling process I get three framework files:
CocoaPodTestFramework.framework
Alamofire.framework
SwiftyJSON.framework
Now When I want to use it a app and created a few test app to test my framework.
Swift: the app is not using cocoapod(normal Xcode Project not workspace), I simply link all the 3 framework and it work.
For Objective-C App, I did the same and it worked.
Now in the another Swift app which uses Cocoapods I have added following in my Podfile
Podfile of Sample App
platform :ios, '9.0'
target 'Cocoapod Test App' do
use_frameworks!
pod 'CocoaPodTestFramework', :path => '/Users/ABCD/Documents/Projects/TEST/CocoaPodTestFramework'
end
Now here the issue comes, whenever I tried to build the app I get
no such module 'Alamofire' in the Referenced framework and in the app it says no such module 'CocoaPodTestFramework'
Having been reading various post/forums/issue since then but unable to figure it out how can it be fixed tried adding pod 'Alamofire' and pod 'SwiftyJSON' in app Podfile as well but still getting the same error.
And also tried adding 'Alamofire' and 'SwiftyJSON' in .podspec (s.frameworks) file of the framework which gives error though.
So I want to know if there is workaround for this or if it is not possible at all?
Read somewhere to use framework project as submodule of the sample app, will this solve the issue?If yes then how can anyone else use this pod if I don't want to share the code I mean without submitting the code only sharing .framework file(Basically Its should like a SDK, source of which I can't share but need to use other pod :P, Even I would like to skip github part searching a way for that as well)
Can anyone help me out of this?
OK...
Here how I have figured it out it may help someone like me...
Podfile
s.dependency "Alamofire"
s.dependency "SwiftyJSON"
The above 2 lines have solved the issue still I don't want to close this thread until I developed the actual SDK to check if this will actually work. :)
I ran through this problem before , I created a dynamic framework that uses pods to accomplish it's process as a chat module , after dragging it to a project it can't see the sub-frameworks and give the same errors you described, finally i figured out that nested frameworks are not allowed in IOS only MACOS ,seems like framework code must be pure code without sub-frameworks to work , wrote a post in Apple forums and they responded like this
I'm trying to create a private pod which uses Google Analytics. I include GA trough CocoaPods with pod 'GoogleAnalytics' but it keeps on failing with the transitive dependencies error.
I know there are already a lot of questions regarding this subject, but none of the solutions offered worked out for me.
Looked at Google's analytics site, but that didn't work out. I've seen this closed GitHub issue and scanned this dicussion.
Briefly looked at this small paragraph, which also clearly passes down the transitive annoyance to GA. At the bottom of the paragraph they say:
This eliminates the transitive dependency from the App -> Segment-GoogleAnalytics -> GA to App -> GA.
And of course, checked SO as well.
A little background info:
I use Cocoapods version 1.0.0
My podfile has use_frameworks! (I need that because I use Swift)
I include the GA pod with pod GoogleAnalytics
I also tried it with Google/Analytics and Google/Analytics ~> 1.3
Also tried adding pod Google before the GA pod
and not that it matters, but:
My Xcode version is 7.3.1
Some solutions say that I need a Cocoapods version after 0.36, and that the use of use_frameworks! should fix it. But as far as I know, and see in the generated Pods project, the GA pod still has a static lib (libGoogleAnalytics.a) and no framework.
This discussion has a lot of opinions and solutions, but as I already said, none work for me. Moreover, at the bottom someone said that this is a Cocoapods issue rather then something Google should fix (something with Cocoapods not taking use_frameworks! into account). But I beg to differ, especially since all other pods give me a framework as they should.
I had the error before when using OpenSSL, but fixed that by adding a compiled OpenSSL framework manually to my pod.
So I'm at a loss now. As for how I can fix this...got no clue whatsoever.
Edit
For now I've sort of circumvented the problem by using Carthage with the framework generated here.
I'm having a problem with integrating a cocoa pod (CocoaLumberjack in this case) into an iOS app and my own frameworks.
The Podfile looks like this:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, "8.0"
target "CommonModule" do
use_frameworks!
# CocoaLumberjack wasn't officially released with Swift support yet
# pod 'CocoaLumberjack'
pod 'CocoaLumberjack', :git => 'git#github.com:CocoaLumberjack/CocoaLumberjack.git', :commit => '6882fb5f03696247e394e8e75551c0fa8a035328'
xcodeproj 'CommonModule/CommonModule.xcodeproj'
end
I have a hierarchy of modules (dynamic frameworks) like this:
CommonModule
ModelsModule (has a dependency CommonModule)
And finally, the main app:
MySwiftApp (dependency both ModelsModule and CommonModule)
Now, CocoaLumberjack is used in several files in CommonModule and works as expected. However, every time I do import CommonModule in any file in ModelsModule, I get the following compile error:
~/Developer/ModelsModule/ModelsModule/SomeFile.swift:2:8: error: missing required module 'CocoaLumberjack'
import CommonModule
^
Any idea how to solve this issue?
UPDATE: Some people Recommend to use Carthage. I would like to avoid that, if possible.
You'll also need to ensure that CommonModule.framework and CocoaLumberjack.framework (and any other frameworks) are listed in the Embedded Binaries section of your application target.
All the new iOS 8-style dynamic frameworks must be embedded within your app—even those that you aren't using directly, but that are dependencies of your dependencies—so you might end up seeing references to items you don't recognize.
Incidentally, there is a new Swift-based logging engine called CleanroomLogger that might make things easier if you're having trouble interacting with CocoaLumberjack from Swift.
I am assuming that CommonModule is swift and that your also using CocoaPods 0.36 as I see your calling use_frameworks!. I'm also assuming that you're using the Obj-C version of CocoaLumberjack, and trying to use it with Swift. That use_frameworks! flag tells CocoaPods to generate frameworks of the pods for linking in your Xcode project. So you need to say at the top of your class
import CocoaLumberjack
instead of using the Swift-Bridging-Header
Here is the blog post on cocoapods.org where they talk about the how to author a pod for the new use_frameworks! flag. Scroll down to the part Common Header Pitfalls
It could also be that your podspec creates a dependency to use CocoaLumberjack, and when linked to your project CocoaLumberjack and CommonModules, but Common Module is not referencing it correctly in the library. To get past that you need to refer to it as a framework when you import it into your Objective-C library
#import <CocoaLumberjack/CocoaLumberjack.h>
I have a framework that has AFNetworking baked into it... I would love to be able to use RestKit but there are obvious duplication problems for the linker because the RestKit source uses AFNetworking too...
Does anyone want to present to me a nice method to allow the two to coexist? Since I can't do much about the other framework I would like to have a walk through of how to get Restkit rockin... thanks!
The typical method in the ObjC realm is to distribute your framework using http://cocoapods.org to manage the dependency chain for you (and eliminate potential duplication of something like AFNetworking).
Here's a nice read: http://blog.chariotsolutions.com/2012/07/using-cocoapods-to-manage-private.html
You can use the following Cocoapods
pod 'RestKit', '~> 0.20.0'
Check the following link for more info
The RestKit framework in turn depends on AFNetworking also.
So, you don't have to install that separately, just install RestKit using pods like this:
platform :ios, '7.0'
pod 'RestKit', '~> 0.24.0'