How to use a Swift library in a Flutter Application? - ios

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.

Related

How to use GoogleMaps in local Swift Package?

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?

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 ` use_frameworks!` to a specific cocoapods pod?

I know if you are using Cocoapods, you should use all pods as framework or static libraries. It's not possible specify some pods using framework and the others using static library. But I just want to have a try to ask or discussion about this problem. Maybe there will be some tricky solutions. ^_^
I am working on a iOS project, Objective-C as the main development language. Now I want to import a swift framework using Cocoapods, I didn't use use_frameworks!, some problems occurs as expected. The Cocoapods version is 1.5.3, Swift 5.0, is there a way or a new version to solve this problem? How about Carthage?
Any discussion is appreciate!
CocoaPods 1.9.0 is adding support for specifying linkage on individual pods. Until then, the only option is Podfile hacks like this one.

React Native Bridge Library for existing Objective C Framework which depends on other iOS Frameworks

I have an Objective-C Framework, which depends on other third party Frameworks through CocoaPods.
i.e A-->B,C,D
I created a react-native-create-library bridge which wraps the code around Objective-C Framework A.
i.e React_Native_A-->A-->B,C,D
I tried creating an example app Example_React_Native_A which links the React_Native_A using the react_native link command. Hoping that it links to the other frameworks added using the CocoaPods.
Unfortunately, this doesn't work in this way. It won't even consider React_Native_A-->A link.
Is there any other way to generate the example app, so that it can link all the required frameworks i.e A-->B,C,D.
If anyone looking for the solution, the way is mentioned in the RNNearBee.podspec here. The wrapper podspec depends on the version of the react as per the local machine installed version and then it depends on the original native podspec.

"Swift is not supported for static libraries" when testing cocoapod

Recently I started creating my pod in Swift. I used pod lib create command and declined offer to use Nimble/Quick as testing library because I hoped to use standard XCTest. However, when I try to run tests, build just fails with message Swift is not supported for static libraries.
I tried to reopen Xcode and clean project, not working.
What should I do in this situation?
Swift don't supported static libraries. If you create lib used objc so you have 2 ways (create static lib and write script for convert to framework) but if you write used swift only one.
So you need create pod. Just create framework in xcode and add files for configurate your project to pod. It't easy, for example you can watch this, I create pod after create project
For swift you need to have Cocoa Touch Framework

Resources