Mixed language framework with Cocoapods - ios

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.

Related

Using Swift library in an Objective-C project

I am working in an Objective-C, iOS project, I used danielgindi Charts library which is a Swift library. I downloaded it using Cocoapods.
I am trying to import the library files into my Objective-C files using 'projectName-Swift.h' as mentioned in this question but I faced an error:
'projectName-Swift.h' file not found
If you have installed Swift library using cocoapods
To import Library in Objective C Code
Use
in Objective C
#import frameworkname;
In Swift
#import frameworkname
If your using cocoa pods try to make sure you have use_frameworks! in your cocoa pods pod file, otherwise the Swift Framework wont work. Also look at this for any other issues that may pop up: link
For making the bridging header visible to your compiler you need a little setup
Go to your Project Build Settings
Search for bridging header
Add the path to your
.h file (usually ProjectName/ProjectName-Swift.h)

How to install CocoaAsyncSocket library into Swift?

There are a lot of information on how to use GCDAsyncSockets with Objective-C but so few with Swift, and almost no information on how to actually install it into the Xcode environment. I tried adding files in the zip file one at a time with File | Add Files to ... Project menu option but still I cannot use the added files with "import GCDAsyncUdpSocket" statement. It says "No such module". There's gotta be an easier way of doing this, right?
Install using CocoaPods by adding this line to your Podfile:
use_frameworks! # Add this if you are targeting iOS 8+ or using Swift
pod 'CocoaAsyncSocket'
CocoaAsyncSocket is Carthage compatible. To include it add the following line to your Cartfile
Carthage/Build/iOS/CocoaAsyncSocket.framework
Carthage/Build/tvOS/CocoaAsyncSocket.framework
Carthage/Build/Mac/CocoaAsyncSocket.framework
Select the correct framework(s) and drag it into your project.
Manual
You can also include it into your project by adding the source files directly, but you should probably be using a dependency manager to keep up to date.
Importing
Using Objective-C:
#import CocoaAsyncSocket; When using iOS 8+ frameworks
or
#import "CocoaAsyncSocket.h" When not using frameworks, targeting iOS 7 or below
Using Swift:
import CocoaAsyncSocket
I following this steps successful use the AsyncSocket class by CocoaAsyncSocket
copy CocoaAsyncSocket project source on github
click CocoaAsyncSocket.xcodeproj file open CocoaAsyncSocket project
copy iOS version AsyncSocket.m AsyncSocket.h AsyncUdpSocket.m AsyncUdpSocket.h file to your use CocoaAsyncSocket project
xcode will tell you create a Bridging-head file,create it
edit the xxx-Bridging-head.h(xxx is your project name)file add #import "AsyncSocket.h"

How can i use the libraries after importing dependencies using cocoapods?

I am facing issues in actually using the libraries contained within the dependancies. I followed the procedure up to the letter but yet xcode gives me errors when i try to import the kit i need to use. Heres what i have done:
create pod file at the project directory
install the pod file with dependancies
open .xcworkspace file created
create a bridging header in objective c
enter path of the bridging header to the build settings
After doing all of this, when i write the import statement (eg. import IMFData) xcode shows that it doesnt exist/ cant be found.
Could somebody shed some light on the what i am missing?
Try adding use_frameworks! to your pod file and then run pod install again. You won't need to use a bridging header then and will be able todo import IMFData alternatively if you aren't using Frameworks when you use the bridging header you don't need to use the import IMFData just access the classes within your swift class.

Swift framework and Cocoapods - integrate static libraries

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

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