The –OC call Swift iOS mixed

If our project is created by OC when you want to use Swift to write a third party, and this is the time to use mixed, when we create the Swift class will have a tip, do not ask us to create a bridge joint document, generally choose to create

The --OC call Swift iOS mixed
asks if the bridge header file is created

Once created, there will be a bridged header file

The --OC call Swift iOS mixed
bridge header file

Then write a function in the Swift file at will

Import, UIKit, class, SwiftClass:, NSObject, {func, sayHello (Name: String) -> String {return, name + sayHello;}}

In the OC class, call the Swift method, first of all, to configure the project, in the “Build Setting” -> “Product Module Name” to add the name of the project

The --OC call Swift iOS mixed
project configuration

Emphasis: introduced in the class that calls the method of Swift

“Import” project name -Swift.h”

Introducing this class introduces all the Swift classes,
, and then calls the methods inside the Swift

#import "ViewController.h" / / into this class introduces all class Swift #import "OCdiaoSwift-Swift.h" @interface ViewController (@end @implementation ViewController) - (void) viewDidLoad viewDidLoad] SwiftClass {[super; *sc = SwiftClass + alloc] / init]; the Swift method system has been converted to OC method *str = NSString [sc sayHelloWithName:@ "CF"]; NSLog (@ "% @", STR);}
The --OC call Swift iOS mixed
results show

Say one more thing: “
” is a class that is written in Swift. If you do not follow the derived class from NSObject or NSObject, what type of compilation will not generate the corresponding conversion class?. Thus the corresponding declaration cannot be found in OC.
, we can go in and have a look at the project name -Swift.h we have.
can see how the apple works, and it automatically generates the corresponding OC code

The --OC call Swift iOS mixed