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
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 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'm working on a swift project until i needed This "Analog Type Time Picker". I downloaded the repo and tried it using Xcode 6.4 and it works fine. But when I started to transfer it to my project, It ask me to create a Bridging-Header and I created one, Also I imported the .h file in the bridging header. My project can see the delegate method so I think its just fine. But the problem is, the variables on the .m file has an error like this:
But if you notice, The last UIButton don't have error. What do you think seems to be the problem?
Put #import <UIKit/UIKit.h> or #import UIKit; at the very top of the .h file where you get these errors
It clearly looks like you do not imported UIKit. Just add #import <UIKit/UIKit.h> or #import UIKit; to the top of your .h file.
Otherwise if you are using both combination (Objective-C & Swift) means you need to add bridging header.
I am trying to use the Stripe SDK in my iOS App but there seems to be a problem. Whenever I try to import it like this:
#import "Stripe.h"
I get the following error:
Stripe.h file not found
But I have the file as shown in the picture attached.
Since Stripe is a framework, you need to import like this.
#import <Stripe/Stripe.h>
In your Objective-C –> Swift Bridging Header you have to import the Objective-C file like the following:
#import "Stripe.h"
Hope that helps :)
Issue
I have a CocoaPod project created using pod lib create. There are some Objective-C classes that can be used inside the example project — I am now trying to add a NSObject subclass written in Swift.
The Swift class was created and the bridging header was added to the classes directory.
I try to import the Swift bridging header into the .m file of another class inside the pod project:
#import "PROFlyoutViewController-Swift.h"
When I compile I get 'ModuleName-Swift.h' file not found
When the import statement is:
#import <ModuleName/ModuleName-Swift.h>
or
#import "ModuleName/ModuleName-Swift.h"
it compiles and is usable!
But...
I return to the file, indexing runs (I assume) and all of a sudden I get:
ModuleName/ModuleName-Swift.h file not found.
Autocomplete is broken on that file and any use of that class shows a warning.
Question
When using trying to use a Swift Bridging header within the files of a pod project, how should it be imported? What do I need to do in order to get autocomplete working and compilable?
Try using #import PROFlyoutViewController; instead as it is an external module.
See the below Example of my TableDemo project
To import Swift code into Objective-C from the same target
Import the Swift code from that target into any Objective-C .m file within that target using this syntax and substituting the appropriate name:
#import "TableDemo-Swift.h"
The Swift files in your target will be visible in Objective-C .m files containing this import statement. For information on using Swift from Objective-C code, see Using Swift from Objective-C.