我有三个类firstVCsecondVCfinalVC
现在,我试图在finalVC中创建一个变量。谁能够在单个变量中同时获取对象类firstVCsecondVC的值。

下面的示例。

class finalVC: UIViewController{
    var objfinal: some-type!
    var objFirstVC: firstVC!
    Var objSecondVC: secondVC!

    override func viewDidLoad() {
        super.viewDidLoad()
        objfinal = objFirstVC
        objfinal = objSecondVC
    }
}

最佳答案

var loginVc:LoginViewController?
var signupVc:SignUpViewController?
var objfinal: AnyObject?


override func viewDidLoad() {
   super.viewDidLoad()

    objfinal = signupVc
    objfinal = loginVc

     objfinal = signupVc
    objfinal = loginVc

    if(objfinal is LoginViewController)
            {
                loginVc = objfinal as! LoginViewController
                print(loginVc.strName)
            }
            else if(objfinal is SignUpViewController)
            {
                 signupVc = objfinal as! SignUpViewController
    print(signupVc.strPicUrl)
            }

        }

10-06 16:01