Let's take a look at the swift call Object-c
First we create a OC class
At the last step, I found a confirmation box, click Yes the system will generate a conversion bridge for Swift and OC.
His naming rules are the project name-bridging-header.h This is the system generated by our direct use.
Next we add a method to the OC class that we just created
#import <Foundation/Foundation.h> @interface testswift2oc:nsobject-(void) testocstr; @end
Implementation method
#import "TestSwift2OC.h" @implementation testswift2oc-(void) testocstr{ NSLog (@ "This is the OC Method");} @end
Then we add a statement to the system-generated file testswiftoc-bridging-header.h.
#import "TestSwift2OC.h"
Well, we can call it in swift, try it.
var testswift2oc=testswift2oc () testswift2oc.testocstr ()
Did it come out already?
Now let's take a look at the OC call Swift
We create a new swift to define a method
Import Uikitclass testoc2swft:nsobject { func testswftstr () { println ("This is the Swift method") }}
Then we first import a header file in the OC class that needs to invoke the Swift class
Project Name-swift.h (this is automatically generated by the system)
Look at the code
#import "Testswiftoc-swift.h"
Then we call in OC
TESTOC2SWFT *testoc2swift=[[testoc2swft Alloc]init]; [Testoc2swift TESTSWFTSTR];
The call is ready.
Apple Development Group: 414319235 Welcome to join the Welcome discussion question
Apple Development Group: 414319235 Welcome to join the Welcome discussion question
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Swift Object-c calls each other