Where can I get CommonCrypto / CommonCrypto file from? - ios

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/

Related

How to use Objective C Cocoapods in Swift Framework

My swift framework has dependency of Objective C Framework. How do I use that ?
When I try to use Bridging Header, I am getting error like Framework Target doesn't support Bridging Header
After my search , I found answers for
How to use Objective C Files in Swift Framework
How to use Objective C Framework with swift project
But I need solution for
How to use Objective C Framework as dependency in Swift Framework ?
Thanks in advance :)
You should do some silly task and you will be able to add Objective-c Framework as well as Objective-C Files.
1) Create a header file and enter headerFile.
2) Set Bridging header path like below.
3) Import Objective-c Framework as well as Objective-C Files like below.
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <GooglePlus/GooglePlus.h>
#import <GoogleOpenSource/GoogleOpenSource.h>
#import <Google/SignIn.h>
#import "FBFetchUserManager.h"
#import "TGLStackedViewController.h"
Just install the library in the project, then make a Bridging Header and import the header file of that framework in the Bridging Header.
Refer this to create Bridging header Link

Swift Project With Objective C Wrapper OpenCV

I have just started to use the openCV library and I am trying to get everything set up. I have a swift project and have dowloaded the framework through cocoa pods. I am trying to import the openCV framework in my objective-c file and I keep getting errors. This is my code and the following are the errors.
#import "OpenCVWrapper.h"
//this line causes the errors
#import <opencv2/opencv.hpp>
#implementation OpenCVWrapper
#end
Errors:
After a little digging, I finally found the solution:
Import any Apple headers AFTER those of OpenCV. So the code should look like this:
#import <opencv2/opencv.hpp>
#import "OpenCVWrapper.h"
You need to add Bridging Header file and import the objective c file in it. after creating a file you need to add the path of this file into Build settings of project Target. Find Bridging Header in build settings. please refer
https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

How to use an Obj-c Library/Custom interface in a Swift Project

Trying to understand how I can use this in my swift project.
https://github.com/Grouper/FlatUIKit
I have copied the classes folder into my project but am not sure how to use the various .h and .m files. How would I go about using these files within my storyboard to use the custom appearances?
Did some searching and wasn't really able to understand the various threads that I found.
A bit of a broad question so I'll try to provide some basics and hopefully that helps.
If you are unaware, there is a whole book written by Apple about how to use objective-c with swift. it's available on iBooks for free Using Swift with Cocoa and Objective-C (Swift 2.1) by Apple Inc
Here is the online link
You will need to create an objective-c bridging header and import your code through the header.
Your bridging header would look like this:
#import "XYZCustomCell.h"
#import "XYZCustomView.h"
#import "XYZCustomViewController.h"
If they don't have any modules then you can use them in your swift code and it should see them. According to Apple:
Use your custom Objective-C code with the same Swift syntax you use with system classes.
let myCell = XYZCustomCell()
myCell.subtitle = "A custom cell"
If you are importing an Objective-c framework then it should already contain and umbrella header file that takes care of the bridging header stuff for you. then you just import the framework name into the class that you are planning on using.
import MyCustomFramework
Link to the apple docs here
For this, you can use a bridging header, which is used to expose Objective C code to swift. To do this, make a new header file in your project. Import the header files you would like to use in the new header file like this:
#import <FlatUIKit/FlatUIKit.h>
And then, in the build settings of your project, define the Objective-C bridging header to be the header file you just created. Now in any swift files that you would like to use the library in just import the classes like this:
import FlatUIKit
Hope this helps!

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

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.

Resources