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
Related
I get No such module 'BRLMPrinterKit' error.
I take a reference from official document https://support.brother.com/g/s/es/htmldoc/mobilesdk/guide/getting-started/getting-started-ios.html to import framework.
Here is my step:
drag BRLMPrinterKit.framework and BRLMPrinterKitW.framework into my framework folder
Check they are in Link Binary With Libraries (remove and drag again)
Check Framework Search Paths (I'm not sure it correct or not)
Check Header Search Paths (I'm not sure it correct or not)
Finally I clean and build get No such module 'BRLMPrinterKit' error.
I have no idea how to fix my import problem, any help would be appreciated. Thanks.
That's not a Swift module, so first, you need to create a bridging header, in which you import <BRLMPrinterKit/BRLMPrinterKit.h>, then you can use the BRLM classes in your Swift files.
Try using CocoaPods to install the framework, it's more convenient and faster.
Your framework supports installation using cocoapods
https://cocoapods.org/
https://github.com/jonathantribouharet/BRLMPrinterKit
using CocoaPods to install the 'BRLMPrinterKit' framework.
add the bridge file.(Targets > Build Settings > Swift Compiler - General > Objective-C Bridgeing Header)
the bridge file.h
#ifndef PtouchPrinterKit_Bridging_Header_h
#define PtouchPrinterKit_Bridging_Header_h
#import <BRLMPrinterKit/BRPtouchBluetoothManager.h>
#import <BRLMPrinterKit/BRPtouchDeviceInfo.h>
#import <BRLMPrinterKit/BRPtouchNetworkManager.h>
#import <BRLMPrinterKit/BRPtouchPrinter.h>
#import <BRLMPrinterKit/BRPtouchPrinterData.h>
#import <BRLMPrinterKit/BRPtouchPrinterKit.h>
#import <BRLMPrinterKit/BRPtouchPrintInfo.h>
#endif
then you can use the framework
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
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/
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."
I've managed to use Objective C library in the Swift AppDelegate.swift file via the bridging header. But the problem is that this library cannot be used in other class from the same project.. How is that?
Say, the enum member MMDrawerSide.Left can be successfully used in the AppDelegate class.
But in the other class the compiler complains:
Use of unresolved identifier 'MMDrawerSide'
What can I do wrong? The steps for making the bridging header were pretty simple and automatic. Here's its contents:
#import "MMDrawerController.h"
#import "MMDrawerVisualState.h"
#import "UIViewController+MMDrawerController.h"
Thank you.
This is a very annoying issue i've had in the past. Try to add the objc bridging header to the swift compiler in the build settings. You may have already done this, it depends on how you made your bridging-header.
Hope this helps.