【发布时间】:2022-11-15 22:00:27
【问题描述】:
我正在尝试在不同的视图控制器中访问 emailAddress 变量,但它始终不在范围内。
我想打电话给
login.emailAddress
在不同的vc中。
这是我的代码供您参考,我知道也有类似的问题,但是我很难将其翻译成我的代码。 .
import UIKit
import GoogleSignIn
let login = LoginController()
class LoginController: UIViewController {
@IBOutlet weak var signInButton: GIDSignInButton!
let signInConfig = GIDConfiguration(clientID: "12345-abcdef.apps.googleusercontent.com")
@IBAction func signIn(_ sender: Any) {
GIDSignIn.sharedInstance.signIn(with: signInConfig, presenting: self) { user, error in
guard error == nil else { return }
guard let user = user else { return }
var emailAddress = user.profile?.email
var fullName = user.profile?.name
var givenName = user.profile?.givenName
var familyName = user.profile?.familyName
var profilePicUrl = user.profile?.imageURL(withDimension: 320)
let userProfile = (fullName, givenName, emailAddress, profilePicUrl)
print("Sign in Sucessfull")
print(fullName!)
print(givenName!)
print(familyName!)
print(emailAddress!)
print(profilePicUrl!)
// If sign in succeeded, display the app's main content View.
let vc = self.storyboard?.instantiateViewController(withIdentifier: "NavigationViewController") as! UINavigationController
self.navigationController?.pushViewController(vc, animated: true)
self.present(vc, animated: true, completion: nil)
}
}
}
【问题讨论】:
标签: swift xcode storyboard