How to use GoogleMaps in local Swift Package? - ios

I'm trying to build an iOS Application which provides AppClips. This means I need to put my code into modules so that the AppClip can reuse some of the code from the main application. The reusable part is using GoogleMaps and that SDK is not yet available via SPM. There is a third-party-fork which makes it SPM-compatible and it kind of works, but it wont let me upload the build because the GoogleMaps SDK gets imported/linked multiple times. Also there is some kind of error stating that it is not "inside the framework folder".
Can anyone provide a solution as to how to use GoogleMaps inside of a local Swift Package? I'm even fine with some kind of hack, because I still hope Google will provide SPM support soon.
So is there a way to use cocoapods or carthage pods or whatever inside a local Swift Package?

Related

How to use a Swift library in a Flutter Application?

Recently I've developed a native ios library using Swift 5.
This library is being distributed using Cocoapods and now that is done I would like to know if there's any method to use that same library in a Flutter application from Cocoapods and which is the best way to do it.
What I've tried so far:
I tried creating a flutter demo app and moving to /ios for running pod init and later configuring my Podfile to point the source of the Pod and after that I did a pod install.
Apparently this works, because if I go to my Runner.xcworkspace and add
import MyLib
to the AppDelegate, it compiles.
The thing is, how do I access the methods and classes of the Pod from my Dart code? Is it possible or I have to manage that interaction directly from Swift?
Thank you very much.
Yes and no. You need to manually write down some boilerplate between Swift and Dart. But this can be simplified by some code generators, for example pigeon.
If you are using other languages like Rust instead of Swift, there does exist more advanced code generators that requires almost zero boilerplate. But there seems none for Swift.

Missing required module 'MLKit' error while using a framework that uses MLKit

Recently I created a iOS Framework called "MLKit Framework" that uses MLKit Face Detection library. In order to achieve that, I just imported the library in Podfile
according to documentation.
As expected, that created a xcworkspace called MLKit Framework. In order to test that new framework, I created an app called MLKitApp and added that app to the same workspace. Then I added the framework MLKitFramework to that app and tried to build it but I get the error statement: "Missing required module 'MLKit'"
as the image below.
Why Am I getting that error? What I'm doing wrong?
Reproducible Example
I created a Reproducible Example here. In order to execute that example execute the following:
Execute pod install for MLKitFramework;
Add MLKitApp to MLKitFramework.xcworkspace;
Add MLKitFramework.framework as a MLKitApp Frameworks, Libraries and Embedded Content;
Try to build MLKitApp.
And voilĂ 
You can't do this because your's "MLKitFramework" have dependency to MLKit.
You should add MLKit framework to MLKitApp additionally.
Have you checked out the ML Kit Vision Quickstart? Please note it contains two apps: one for swift and another for objective-c. You check check out the swift app for your purpose - it contains face detection feature. The Vision Quickstart is similar to your MLKitApp and shows you an example how to integrate with ML Kit cocoapods directly without needing to introduce an "MLKitFramework" or manually manage dependency configuration. Instead, you should let CocoaPods manage that. You can use this Quickstart as a template for implementing your own app.
I don't now if this helps after all this time, but for future references here it goes:
Google hides the header, so you have to manually specify the header you want to add so your test can find it.
If you go to: Project> targets YourProjectTest > Build Settings > Search Paths > Header Search Paths and add:
"${PODS_ROOT}/Path-to-the-Header-in-your-Pods-Folder/Soucers"
In my case it was:
"${PODS_ROOT}/GoogleMLKit/MLKitCore/Sources"
It worked big time for me.
I hope it helps :)

Main app can't reference framework used in React Native Library

I need some advice about building react native library that using framework. I'm trying to build one using this library. My react native library contains these files:
Sample-Bridging-Header.h
Sample.m
Sample.swift
Sample.xcodeproj/
Utilities/Utility.swift
Utilities/Helper.swift
Test.framework
Inside my Utility.swift and Helper.swift, I import library Test and there is no issue there.
However, when I build the sample app which uses the library, it will not build and it gives the error no such module 'Test'.
So it looks like if the main application try to use the react native library, and if the library uses a framework, the main application can't reference the framework. I'm not sure if this is the right approach or not.
I built react native library before and it worked for me but I never have to reference any framework.
Appreciate any help! Thanks!
Actually I just figured out how to handle this. I just need to update the podspec to include the framework by using s.ios.vendored_frameworks = ios/Test.framework.
Once I did that, I run pod install again for my example project. So now it can pull the framework in properly.

How can I use a 3rd party Framework inside my CocoaTouchFramework and my consuming App?

I am developing an iOS App and a CocoaTouchFramework. The iOS App depends on the framework. My goal is to use a 3rd party Framework (in this case AlamoFire) inside my CocoaTouchFramework. According to this Stack Overflow link it is discouraged to have a Framework embed another framework. The way I understand it is that the consuming iOS App (the app which depends on the framework) needs to provide the 3rd party dependency and that my framework can reference that dependency. I don't know how to set this up in Xcode however. Here is what I have currently set up in Xcode:
AlamoFireApp is the actual App and AlamoFramework is my own Framework that will use AlamoFire to perform various network requests. I embedded the AlamoFire dependency into the App. How can I use AlamoFire in the Framework now? I've tried linking to AlamoFire from within the Framework (Adding Alamofire.framework) in the Link Binary With Libraries section) but I always get the No such module 'AlamoFire' error when I try to import AlamoFire in my Framework's classes.
Any help is appreciated.
#cbbcloud you can make your own cocoa pods using alamo fire. All you have to do is add them as dependency in pod spec. And then you can import the use the framework to build your framework.
Pod::Spec.new do |s|
s.name = 'YourFrameworkName'
//other info
s.dependency 'Alamofire'
end
If you are new to cocoapods , follow this link
https://guides.cocoapods.org/making/index.html
Ok I've found a way to do it. I was able to solve the problem by dragging the AlamoFire.Framework into my framework (in this case, AlamoFramework) in Xcode. The important part that makes this work is to check the 'Copy items if needed' checkbox.
After checking this, the compiler can resolve the Alamofire module and there are also no linker issues. However this approach seems to contradict the recommendation of Rob Napier in his answer to this question that states:
The only appropriate time to link dependencies is at the application layer.
I haven't done full-time iOS development for very long so if anyone has any input they can give to clear up this issue, that would be great. But my problem has been fixed for now so I can continue with development.

Creating framework that requires (depends on) another framework

I'd like to create a framework using Cocoa Touch Framework Project in Swift. However, I'm building this framework on top of another framework called RNCryptor, which is Objective-C based. I've seen various tutorials on how to create a framework in Xcode but none has covered a framework with its own dependency.
I tried to create a framework project and then using CocoaPods to manage its dependencies. However, there are errors appeared: 'Check Dependencies' Unable to run command...'
So the question is: is it possible to create a framework on top of another framework in Xcode. And if so, how?
Frameworks should never embed other frameworks directly. This leads to collisions if the importing project or any other framework also includes that framework. Instead, you need to tell your consumer that they also need to include your dependency. CocoaPods will do this for you automatically, so you should let it. (If you're having trouble with CocoaPods dependencies, you should ask a question about that and get it cleared up. The whole point of CocoaPods is to manage these kinds of things.)
Note that I will be releasing the Swift version of RNCryptor into beta today (or tomorrow, but I really hope today). This version bridges to ObjC and will be the preferred version going forward. (The ObjC version will continue to be available of course for projects that cannot or don't want to include Swift.)

Resources