我有一個類在我SignInViewController.swift:如何將值從單獨的類傳遞到AppDelegate?
class CredentialState: NSObject {
static let sharedInstance = CredentialState()
var signedIn = false
var displayName: String?
var photoUrl: NSURL?
}
我想用變量signedIn在AppDelegate中使用if-else語句驗證用戶身份。目前,我有一種方法將視圖控制器設置爲CustomTabBarController(自定義編程)或 SignInViewController(製作故事板)。 if語句基本上會說如果該值爲false,則將控制器設置爲登錄屏幕,如果是true,則轉到標籤欄屏幕。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
FIRApp.configure()
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.makeKeyAndVisible()
// Main view controller is inside of customtabbarcontroller, which gives a tab overlay
// window?.rootViewController = CustomTabBarController()
// Sets the main view to a storyboard element, such as SignInVC
let storyboard = UIStoryboard(name: "SignIn", bundle: nil)
let loginVC = storyboard.instantiateViewControllerWithIdentifier("SignInVC") as! SignInViewController
self.window?.rootViewController = loginVC
return true
}
這完美地工作。謝謝! – About7Deaths
不客氣。很高興我能幫上忙 :) –