Import RNCryptor to project - ios

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."

Related

Where can I get CommonCrypto / CommonCrypto file from?

I have a problem with importing CommonCrypto/CommonCrypto or CommonCrypto/CommonDigest. I need a SHA256 for my Swift code.
I found CommonCrypto github site in Cocoapods.
https://github.com/AlanQuatermain/aqtoolkit
So I have downloaded the file from above.
But I'm getting errors about ARC (I have added Bridging-Header like other tutorials do.)
The header file's name is NSData+CommonCrypto.h and NSData+CommonCrypto.m.
It's not a CommonCrypto/CommonCrypto or CommonCrypto/CommonDigest
Where can I download and get the exact file CommonCrypto for SHA256?
No additional files are required. You need a bridging header first of all, which you already have but for those who don't the easiest way to achieve this is to add an Objective-C file to your project and to accept when it offers to create a bridging header. You can then either import the whole of CommonCrypto (thanks #zaph - see comments) to the bridging header:
#import <CommonCrypto/CommonCrypto.h>
Or the constituent parts:
#import <CommonCrypto/CommonCryptor.h>
#import <CommonCrypto/CommonDigest.h>
#import <CommonCrypto/CommonHMAC.h>
#import <CommonCrypto/CommonKeyDerivation.h>
#import <CommonCrypto/CommonSymmetricKeywrap.h>
You can now use CommonCrypto in Swift. For example code see here.
Edit
In Xcode 10 a bridging header is no longer required to import CommonCrypto in Swift. You can simply use:
import CommonCrypto
In fact, you don't need to compile any file to using CommonCrypto, just import it in your project.
or using some wrapper in Swift, just like https://github.com/soffes/Crypto
Let's back to CommonCrypto file,Apple have released it's source code in https://opensource.apple.com/source/

Can't use Objective C framework imported within Bridging Header

Usually I am using CocoaPods (with use_frameworks!) in order to manage my frameworks, but this PDF library (FastPdfKit) does not support CocoaPods, so i added it manually in "link binary with libraries" along with its dependencies. After that I let xcode create a bridging header for me (I created a .m file, and xcode created a bridging header automatically).
I imported the header in the bridging file like this #import <FastPdfKit/FastPdfKit.h>, but I can't acces any method/class from my swift files... (Use of undeclared type 'ReaderViewController' where ReaderViewController is a subclass of UIViewController in the framework).
I've also tried importing like this #import 'FastPdfKit.h" still gives the same errors.
To import Objective-C code into Swift from the same framework, go to Build Settings > Packaging and make sure the Defines Module setting for that framework target is set to “Yes”.

Using CocoaPods and Obj-C Bridging Headers

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.

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.

Why does the SimpleAuth CocoaPod not work with Swift Bridging Header file?

I cannot seem to get the SimpleAuth CocoaPod to work in a my swift project. I have:
created a bridging header file
with #import <SimpleAuth/SimpleAuth.h> and
edited the swift compiler - code generation section in build settings
Am I supposed to manually fix the 15 Swift Compiler Errors (mainly 'unknown type name NSString' and 'Expected a type') or is this a sign I am doing something completely wrong?
Thanks
#import <Foundation/Foundation.h>
in your header file
I just went back to several projects with bridging headers to import obj C frameworks and they all appear to have the same issues you have. It looks like a line by line fix for those.

Resources