我有三个课程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
}
}
答案 0 :(得分:2)
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)
}
}