Using CocoaPods and Obj-C Bridging Headers - ios

When you include 3rd party Obj-C libraries and use the Obj-C Bridging Header, you are able to directly use the integrated libraries without the import statement.
//Bridging header
#import <Parse/Parse.h>
#import <Bolts/Bolts.h>
//Now, within the project, I can make calls to the Parse library without imports.
However, if I include 3rd party Obj-C libraries using CocoaPods, this doesn't seem to be the case. I needed the import statement for each file to use the library.
Is there a way to rectify this?

You can achieve this using Bridging Header similarly as you had it without Pods, follow the steps.
Keep your bridging header at the project home directory.
ie., if your project name is SampleProject. Usually you keep your Bridging header at the position SampleProject->SampleProject->Bridging-Header.h
But now, keep it at SampleProject->Bridging-Header.h
Get your pods library header file's path and import it inside your Bridging-Header.h file as usually.
(Refer this link for details.)
Remaining things will work like a charm.

Related

CocoaPods 1.0.1 still requires bridging header with Swift

In this example project, comment out the one #import line in BridgingHeader.h and it will yield an error of unresolved identifier in AppDelegate.swift
https://github.com/lacyrhoades/GLSlideshow/tree/stackoverflow
As another approach, and what I understand is the "correct" approach, if in AppDelegate.swift we add import GoogleCastRemoteDisplay this does NOT fix the error, but it makes a new one saying no such module GoogleCastRemoteDisplay
Is this a problem with the library's podspec? I want to make my own Pods but I am confused: When is a bridging header needed for a Pod, when is it not?
A bridging header is required when you use Obj-C based pods. If you use a swift based pod, no bridging header is required.
An easy way to add it is to create a new Obj-C based class in your swift based project (name it whatever. It doesn't matter). When you do that it will ask you if you want to automatically add the BH. Say yes and then delete the class you just created leaving the BH. Import all Obj-C headers here.
Hope that helps.

How to import Objc Files into my Swift files within my custom cocoapods framework?

Simple explanation. I have created my own pod with name BSSelectableView, but within I need to use two files written in Objective-C. What do I need to achieve?
I need to make it visible within my Swift files, and also for people who will install my pod.
Your Target needs a Bridging Header.
This is an Objective-C-Header-File with the name [TargetName]-Bridging-Header.h
Within this file, you have to #import all Objective-C-Headers you want to use in your Swift-Files.
You don't have to import anything in your Swift files.
More information about Swift and Objective-C mixed projects
You need to create a [TargetName]-Bridging-Header file in your project.
import all the header files in bridging header file
Now you can use all objective c file in swift.

Import RNCryptor to project

I try to import RNCryptor to my project to encrypt some string. But I have trouble to understand how to import that to my objective-c project. I copied the RNCryptor/RNCryptor.swift and RNCryptor.h by drag and drop in to my project. Then it "created a bridging header". After that I tried to debug but I have 38 error messages like: Use of unresolved identifier 'kCCKeySizeAES256' or Use of unresolved identifier 'CCPBKDFAlgorithm'. How can I fix that and how would I use it in a viewController.h file? Normally with #import "RNCryptor.h"
https://github.com/RNCryptor/RNCryptor#obj-c
I think you need to add #import "RNCryptor/RNCryptor.h" to the bridging header file, did you do that?
See the RNCryptor Swift branch
The Bridging Header
CommonCrypto is not a modular header in Xcode 7. This makes it very challenging to import into Swift. To work around this, the necessary header files have been copied into RNCryptor.h, which needs to be bridged into Swift. You can do this either by using RNCryptor as a framework, adding #import "RNCryptor/RNCryptor.h" to your existing bridging header, or making RNCryptor/RNCryptor.h your bridging header in Build Settings, "Objective-C Bridging Header."

Add Bridging-Header inside .framework

I want to know if it is possible to add a Bridging-Header.h inside a .framework.
My goal is to have my framework compliance for swift.
I don't have find solution to add bridging header file inside my framework but have find other solution. That is to explain how to create a bridging header file without import Objective-C file.
For people who want to do this be careful when you indicate the path in Objective-C Bridging Header under Swift Compiler - Code Generation to your bridging header file. It is important to to this in your Target build setting and not in your project build setting else you will be have an error.

Xcode issue importing header file

I've an iOS project, with cocoapods for external libraries management.
When I try to import an header file from that, instead of the right library, Xcode imports the file (with the same name) from another project/folder.
Furthermore the file is different.
If I want to reference to the right header I must write the absolute path
#import "Pods/CHCSVParser/CHCSVParser/CHCSVParser.h"
Why?

Resources