我有三个类firstVC
,secondVC
和finalVC
。
现在,我试图在finalVC
中创建一个变量。谁能够在单个变量中同时获取对象类firstVC
和secondVC
的值。
下面的示例。
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)
}
}