calling .cpp files from Objective-C class .m - c++

I have a few classes written in c++ which needs to be integrate with my iOS project written in Objective-C. I got a Mac (C++) project from my client to integrate with my project. I need to call the methods in .cpp class from Objective-C class with NSNotificationCenter or some other way which is better do it?

If you make a file with extension .mm you can use both Objective-C and C++ inside that one. It can quickly get messy so i usually try to keep the C++ touchpoints contains in a few .mm files so the whole thing won't be a mix of Objective-C and C++ and c code.

Related

Is it possible to include framework in C++ project in Xcode?

I have a C++ project generated from Cmake to Xcode. My project is just some static and dynamic libraries. I want to include some 3rd party frameworks to it.
Is it possible? Is there any chance to include? Or I should completely redesign the project to Cocoa app?
I haven't access to the framework source code.
Work with Xcode 9.2.
No, you can't use Cocoa frameworks in pure C++ project.
But you can just create an obj-c project and include all of your existing sources inside - everything will work. Just remember to use .mm extension for the source files, calling C++ code.
You can use swift as well, but that will require to create a wrapper for C++ code.

Can you still use C++ in Xcode?

I want to learn C++ on my Mac computer. A lot of forums recommend using Xcode, but when I downloaded it I realized that it only has options for Swift or Objective-C. Is there still a way to use C++ in Xcode?
The parts of a problem that interact with system APIs for making an app have to be Swift or Objective-C. (As such, the project templates that give you the bare skeleton of an app to get started with are only Swift and ObjC.)
However, an Objective-C app can use C++ internally. Just create .mm files instead of .m (or rename the ones you have from the project template) so that the compiler knows you're writing Objective-C++. Then you can write ObjC classes that create C++ objects or call into C++ libraries, write C++ classes or templates that store pointers to ObjC objects, etc.

CoreBluetooth with C++

I need to send data via bluetooth from iOS app into a C++ application. So
I have to implement Bluetooth module in c++, in iOS app using Corebluetooth framework.I created a wrapper class of bluetooth module for C++ app. I can call the iOS function from C++ application but, C++ doesn't have Corebbluetooth. Is it possible to create wrapper class for corebluetooth to use with C++ ?
If possible how to create the same?
Yes, that is possible.
You just need to create an Objective-C++ wrapper that forwards the messages to your C++ code. Objective-C++ allows you to use C++ code in your Objective-C classes. To use it, you either need to set the extensions of source files with your Objective-C wrapper from .m to .mm or set the sources to Objective-C++ in the File Inspector in Xcode.

Opening an objective c window from a C++ app

I have a C++ app that needs to send messages to google API's to do this I need to authenticate. I have a standalone Objective C authentication utility that is allowing me to do the authentication, but i'm not sure how to integrate it into the C++ app.
How do a trigger an Objective C window to load from C++
You can mix Objective-C and C++ code using Objective-C++. Simply just rename the file that uses both languages with an extension of .mm. Any other files that imports any Objective-c++ files will need to be renamed to .mm as well.

using c++ (.cpp) with objective-c (.m)

sorry for my english is not good.
I'm trying to use pure c++ code in my iOS project but I have the next issues:
I create one new file product.cpp + product.h, I create his own methods and atributes, and I want to use this class in my viewcontroller.m but dont run, I change the extensión of the viewcontroller.m to viewcontroller.mm but dont run but if I change the extension of the appDelegate.m to appDelegate.mm this is ok and run.
My question is I always have to change mi files to .mm if I want to use .cpp?
:/
Generally yes, a file extension of .mm tells Xcode to invoke the Objective-C++ compiler, whereas .m tells the compiler to invoke the Objective-C compiler. You can set the compiler type on a per-file basis using the file-settings pane on the right (so you could force Objective-C++ compilation on a .m file), but this is non-intuitive and is likely to confuse future maintainers.
If you're willing to consider some advice from a long-time C++ and Objective-C user, I've done a lot of mixing of the two and over time it's more trouble than it's worth. You're much better off if sticking purely to Objective-C, and if you have some C++ library that you just have to integrate, then make a C wrapper for it.
It used to be the case that Xcode analyzer only worked on Objective-C files, not Objective-C++, so you'd lose a lot of the value that tool provides by writing Objective-C++ files. I'm not sure if Apple has changed it in the year or so since I last wrote any Objective-C++ but I imagine there isn't a lot of reason for them to. Stick with Objective-C if you can because the Analyzer is extremely helpful.