Files
SubView.h (A header file for getting call)// The class from C++ call class SubView { public: // Getting call from C++ static void callObjC(); };
SubView.mm (A source file for getting call)
#import "SubView.h" // Not in header file. @interface ClassObjC : NSObject + (void)testingMethod; @end // Objective-C class in source file as normal way @implementation ClassObjC //-------------------------------------------------- // [Objective-C] for testing //-------------------------------------------------- + (void)testingMethod { NSLog(@"I was called from C++"); } @end //================================================== // [C++] Call the method of Objective-C class //================================================== void SubView::callObjC() { [ClassObjC testingMethod]; }
MainView.cpp (For calling Objective-C)
#include "SubView.h" void MainView::mainFunc() { SubView::callObjC(); }
Short Description
This is like portal for C++ in Objective-C file.The number of functions is here.
- MainView::mainFunc()
- SubView::callObjC()
- [ClassObjC testingMethod]
Such as, if your project has Objective-C file, replace the class interface to the source file from the header file, and just add the C++ coding then done. Also remind this file extension need to be ".mm".