If there is a OC class Ocviewcontroller:uiviewcontroller
There are two methods in the class
Swift calls to OC or C's mash-up are more commonly used, and in turn few calls are made. This only writes the way Swift calls OC and C.
OC Function Declaration
-(void) Testoc;
C function Declaration
void Testc ();
Realize:
void Testc ()
{
printf ("Testc .............");
}
-(void) Testoc
{
NSLog (@ "\ntestoc ..............)");
}
Adding the OC class to the SWIFT project, the system automatically generates an. h file named: Project name-bridging-header.h
Introduce the header file of the Oc/c class in this area
#import "OCViewController.h"
So you can use it directly.
Class Viewcontroller:uiviewcontroller {
Override Func Viewdidload () {
Super.viewdidload ()
Instantiating classes
var OCVC = Ocviewcontroller ()
Swift calls OC function
Ocvc.testoc ()
Swift calls the C function directly
TESTC ()
Additional setup after loading the view, typically from a nib.
}
}
Ways to use OC/C in Swift projects