Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I have not learned Swift and I am not going to. However, this should work as all the C++ is confined to its own file. Swift does not get along with C++. I have a couple of apps in the App Store. This is what I had to do to get it to work with iOS 9 and the latest Apple hurdle...bitcode. Download the prebuilt iOS framework. Add it to your project. Do not add it to the binary section, it wont work. Add a C++ file to your project, leave the .cpp file alone and add the following to your .hpp file.

#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif

Now add this to your main ViewController

#import "opencvBridging.cpp"
#import <opencv2/imgcodecs/ios.h>

I have not learned Swift and I am not going to. However, this should work as all the C++ is confined to its own file. Swift does not get along with C++. I have a couple of apps in the App Store. This is what I had to do to get it to work with iOS 9 and the latest Apple hurdle...bitcode. Im assuming you are using Xcode as your IDE. Download the prebuilt iOS framework. Add it to your project. Do not add it to the binary section, it wont work. Add a C++ file to your project, leave the .cpp file alone and add the following to your .hpp file.

#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif

Now add this to your main ViewController

#import "opencvBridging.cpp"
#import <opencv2/imgcodecs/ios.h>

I have not learned Swift and I am not going to. However, this should work as all the C++ is confined to its own file. Swift does not get along with C++. I have a couple of apps in the App Store. This is what I had to do to get it to work with iOS 9 and the latest Apple hurdle...bitcode. Im assuming you are using Xcode as your IDE. Download the prebuilt iOS framework. Add it to your project. Do not add it to the binary section, it wont work. Add a C++ file to your project, leave the .cpp file alone and add the following to your .hpp file.

#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif

Now add this to your main ViewController

#import "opencvBridging.cpp"
#import <opencv2/imgcodecs/ios.h>

Make sure to change your ViewController.m file to a ViewController.mm file. Just click on the name of the file in your Project Navigator (left side up at top) and add the m.

I have not learned Swift and I am not going to. However, this should work as all the C++ is confined to its own file. Swift does not get along with C++. I have a couple of apps in the App Store. This is what I had to do to get it to work with iOS 9 and the latest Apple hurdle...bitcode. Im assuming you are using Xcode as your IDE. Download the prebuilt iOS framework. Add it to your project. Do not add it to the binary section, it wont work. Add a C++ file to your project, leave the .cpp file alone and add the following to your .hpp file.

#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif

Now add this to your main ViewController

#import "opencvBridging.cpp"
#import <opencv2/imgcodecs/ios.h>

The import opencvBridging.cpp is what I named my C++ file I added, so replace this with your filename. Make sure to change your ViewController.m file to a ViewController.mm file. Just click on the name of the file in your Project Navigator (left side up at top) and add the m.