Swift framework and Cocoapods - integrate static libraries - ios

I created a cocoa touch framework with Swift as the preferred language.
On this framework I need to import static libraries, so I created a podfile and imported the pod using use_frameworks!
I created a bridging header and also added the pods source as header search path since it couldn't find the pod's header.
The framework compiles fine and I have no issues.
So I created a pod spec for the framework and created a sample app in swift. I had the framework as development pod in my podfile. Now I get
Include of non-modular header inside framework module in my bridging header import of the static library public header.
I understand since it's a static library we cannot build the touch framework, but what would be the work around to have a touch framework with static libraries in them written in Swift.
PS I have set Allow Non-modular Includes in Framework Modules to Yes

To answer my original question. It seems to be an issue with cocoapods(0.36.2) for vendor libraries where there is no implementation file.
There is a hack to get this working and you can take a look at this github issue

Related

How to use Obj-C Framework code in Swift Framework?

How to use Obj-C Framework code in Swift Framework?
Is it possible or I need to mix them in a single Framework?
I have code for both Frameworks. I connect them manually without CocoaPods, Carthage or Swift Package Manager. Bridging header cannot be used inside of a Framework, only in App Target. Google says that I need to use modulemap file. In all examples I found they create their own modulemap files and put them near the Swift framework code. I tried to use both my own modulemap file and existing one inside ObjCFramework.framework/Modules. I use them by adding a path to the modulemap file to SWIFT_INCLUDE_PATHS build setting of my Swift Framework. I also tried to #import Obj-C Frameworks Ubrella Header to Swift Frameworks Ubrella Header with no luck. Of course I added the Obj-C Framework target to my Swift Framework target dependencies, the framework itself to Frameworks and Libraries and the path to it to Framework Search Paths. I didn't put anything to Header Search Paths to avoid "Include of non-modular header inside framework module", but that didn't help. CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES build setting doesn't help too. DEFINES_MODULE is set to YES.
Now I'm in endless loop of several errors:
Include of non-modular header inside framework module 'ObjCFramework': '/Users/bond/Library/Developer/Xcode/DerivedData/SwiftFramework-aqidpocynynsvdgtrqwukanwqkxf/Build/Products/Debug-iphoneos/ObjCFramework.framework/Headers/View.h'
Module 'ObjCFramework' was built in directory '/Users/bond/Library/Developer/Xcode/DerivedData/SwiftFramework-aqidpocynynsvdgtrqwukanwqkxf/Build/Products/Debug-iphoneos/ObjCFramework.framework' but now resides in directory '/Users/bond/Library/Developer/Xcode/DerivedData/SwiftFramework-aqidpocynynsvdgtrqwukanwqkxf/Build/Products/Debug-iphoneos/ObjCFramework.framework/Modules'
No such module ObjCFramework
underlying Objective-C module not found
In brief this is described here: https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_objective-c_into_swift, "Import Code Within a Framework Target" chapter.
If the Defines Module setting is turned on in your framework target, modern Xcode puts Modules folder in the framework, with Swift versions of all you ObjC public interfaces, making ObjC stuff available either for external Swift code that links your framework or Swift code of the framework itself.
This does not depend on whether your framework target contains any swift code.
Just add you ObjC header to framework target, mark it as Public in "Target membership", include in framework Umbrella header and build.

Mixed language framework with Cocoapods

I'm creating Swift framework that will be distributed via Cocoapods. Inside MyFramework I use few frameworks installed via Cocoapods. Importing frameworks written in swift works fine, but I get trouble importing objc framework. I want to use CardIO inside MyFramework and add it as pods submodule, so user can optionally install it like pod 'MyFramework/CardIO'. After installing CardIO pod in MyFramework, I try to import it in MyFramework-umbrella-header like:
#import "CardIO/CardIO.h"
but get the error:
"Include of non-modular header inside framework module ".
I also check this answer, but this doesn’t work when importing objc framework. Any idea is it possible to import objc framework that installed via Cocoapods to Swift framework?
[FIXED]: The problem was in CardIO podspec, they import only .h files as source_files. So after including .m files to source files: .source_files = 'CardIO/*.{h,m}' Cocoapods generate CardIO modulemap, then it's possible to import CardIO module in Swift framework.

How to build a Cocoa touch framework in iOS?

I want to build a Cocoa touch framework in iOS. My framework named as 'MyFramework' which depends on third party frameworks like 'GoogleWebRTC'.
I tried adding this through cocoa pods and also with drag into MyFramework project. But the issue is when I import MyFramework into any other Project, it gives error:
Module 'WebRTC' not found
I have also seen that Apple discourage umbrella frameworks:
Why are umbrella frameworks discouraged?
Then:
I want to understand how I can include this GoogleWebRTC.framework or any other third party lib. in MyFramework project and distribute to others.
Help is Appreciated!
Solution for me was that I have to explicitly add GoogleWebRTC in the app with my framework.
And if your framework can install by pods then you can mention your dependent third parties lib. in podspec file as below:
s.ios.dependency 'dependent framework pod'

Sharing code between iOS Project and custom created iOS Framework

I have written a framework that make use of SAMKeychain. This frameworkA is used inside the an iOS project.
The iOS project in return has some additional classes that uses the same SAMKeychain. I am trying to find a way to refer the SAMKeychain in the framework and include as a dependency(But do not include SAMKeychain sources) inside the framework.
I tried referencing just the header files of SAMKeychain in the framework and try to build the framework but It failed with linking error _OBJC_CLASS_$_SAMKeychain
What is the best way to share third party code between the framework and iOS project
The solution was to use dynamic frameworks . So when frameworkA is made it should be dynamic and the Pods it contains that is SAMKeychain should also be dynamic to do that you use
use_frameworks! in Podfile which will create SAMkeychain.framework for the Pod SAMkeychain.
After the frameworkA binary is created in the iOS project you have to add both frameworkA and SAMKeychain.framework as embedded binaries. And this will work just ok.
Note that if you don't use use_frameworks in the Podfile it would generate a static library of the pod which will be included in the binary of frameworkA.
Hope this helps someone!

How to use Cocoapods in a Swift framework?

I am trying to create a new Cocoa Touch Framework for iOS in Swift, using some libraries from Cocoapods, but I can't have it work.
I know there are some opened questions about that, but none of them seem to fix my problem.
For testing purposes, I just created an empty Cocoa Touch Framework, installed Cocoapods and added the 'MBProgressHUD' pod.
Then, as documented by Apple ('Importing Code from Within the Same Framework Target' section), I imported the MBProgressHUD header in my umbrella header like that:
#import "MBProgressHUD.h"
But when I compile, I have this error:
include of non-modular header inside framework module
I did set the 'Allow Non-modular includes in Framework Modules' setting to Yes, but it doesn't have any effect.
Is there any way to use CocoaPods in a Swift Framework?
I found the solution, so I will let it here in case someone else has the same issue.
So, Cocoapods supports iOS frameworks since version 0.36, and as it's said in their blog, to use it in a framework, you just have to add this line in your Podfile:
use_frameworks!
After that, in a Swift framework, you don't need to include the .h files in your umbrella header, but you do need to import the module wherever you need it, for instance:
import MBProgressHUD
This is working for me, hope it helps!
Using 'Objective-C bridging header' we can make use of Objective-C frameworks in Swift.
Refer the following, It will explain how to make use of Objective-C framework(For example Parse framework) in Swift.
• Link1
• Link2

Resources