IOS development of OC and Swift mixed programming OC into Swift class and Swift into OC - with a property value

1 When choosing Swift for a new class, it will appear whether to choose to generate a header file like this, and choose to generate, (used by the class that calls the Oc from the Swift class)

2 Declare the project name in the Oc class plus -Swift.h similar to

3 The method to enter the next interface is the same.

present to the Swift interface:

 SwiftViewController *pushSwift = [[SwiftViewController alloc] init];

    //[pushSwift leftReturnBtn];

    [self presentViewController:pushSwift animated:YES completion:nil];

Swift interface returns to Oc interface 

self.dismissViewControllerAnimated(true, completion: nil)

 

Next, let's talk about how to jump from the Swift interface to the OC interface

1 Declare the OC class to be entered in the project name-Bridging-Header.h class

 As shown in the figure:

 

Next, you can call it in the Swift class

as follows:

let nextVc : ViewController!

        nextVc = ViewController.init()

        self.presentViewController(nextVc, animated: true, completion: nil)

 

 

Methods for declaring properties that can be called by other classes

var trantsStr : String = String()//"The declared attributes cannot be associated, only copy";

 

 

I will post the full project link in the comments

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324602320&siteId=291194637