importUIKitclassViewController:UIViewController{// Create a class variable for designation method to visit its attributes.let labelOne =UILabel();// Create a class variable for clourse to visit.var mainContent:String="";@objcfuncmainListener(){let svc =SecondViewController();// Create an optional closure to get the variable.
svc.closure ={(data:String)inself.mainContent = data;self.labelOne.text =self.mainContent;print(self.mainContent);}self.present(svc, animated:true, completion:nil);}overridefuncviewDidLoad(){super.viewDidLoad()// Do any additional setup after loading the view.// let labelOne = UILabel(frame: CGRect(x: 30, y: 120, width: 240, height:30));
labelOne.frame =CGRect(x:30, y:120, width:240, height:30);
labelOne.text ="Fuyang Normal Colleage";
labelOne.textColor =UIColor.purple;
labelOne.font =UIFont.boldSystemFont(ofSize:20);self.view.addSubview(labelOne);let butttonOne =UIButton(type:UIButton.ButtonType.system);
butttonOne.frame =CGRect(x:200, y:400, width:100, height:30);
butttonOne.setTitle("ButtonOne",for:UIControl.State())self.view.addSubview(butttonOne);
butttonOne.addTarget(self, action: #selector(mainListener),for:UIControl.Event.touchUpInside);}}
SecondViewController.swift
importUIKitclassSecondViewController:UIViewController{// Create an optional clourse.var closure:((String)->Void)?;@objcfuncsecondListener(){// Set the content into clourse.self.closure!("Fuyang Normal University");self.dismiss(animated:true, completion:nil);}overridefuncviewDidLoad(){super.viewDidLoad()self.view.backgroundColor =UIColor.orange;let butttonOne =UIButton(type:UIButton.ButtonType.system);
butttonOne.frame =CGRect(x:100, y:300, width:120, height:30);
butttonOne.setTitle("Second",for:UIControl.State())self.view.addSubview(butttonOne);
butttonOne.addTarget(self, action: #selector(secondListener),for:UIControl.Event.touchUpInside);// Do any additional setup after loading the view.}}
ViewController.swiftimport UIKitclass ViewController: UIViewController{ // Create a class variable for designation method to visit its attributes. let labelOne = UILabel(); // Create a class variable for clourse to visit. var m