2016-06-20 10 views
1

私はSignInViewController.swiftでクラスを持っている:別々のクラスからAppDelegateに値を渡すには?

class CredentialState: NSObject { 
    static let sharedInstance = CredentialState() 
    var signedIn = false 
    var displayName: String? 
    var photoUrl: NSURL? 
} 

私はのif-else文でAppDelegateでユーザーを認証するために、変数signedInを使用したいと思います。現在、私はCustomTabBarController(プログラムで作成されたカスタム)にviewcontrollerを設定する方法がありますまたは SignInViewController(ストーリーボード製)。 ifステートメントは、値がfalseの場合、コントローラをサインイン画面に設定し、それが真であればタブバー画面に進みます。

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 
} 

答えて

1

私が正しくあなたを理解している場合:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    FIRApp.configure() 

    // Override point for customization after application launch. 
    window = UIWindow(frame: UIScreen.mainScreen().bounds) 

    // check login state 
    if CredentialState.sharedInstance.signedIn { 
     // Main view controller is inside of customtabbarcontroller, which gives a tab overlay 
     window?.rootViewController = CustomTabBarController() 
    } else { 
     // 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 
     window?.rootViewController = loginVC 
    } 

    window?.makeKeyAndVisible() 
    return true 
} 
+0

に答えることができました

if(credentialState.signedIn == true) ... 

希望。ありがとう! – About7Deaths

+0

ようこそ。お役に立てて嬉しいです :) –

1

を私はあなたが求めているもののようにわからない、まだ私はそれに答えることをしようとするでしょう。

credentialState : CredentialState = CredentialState() 

変更またはAppDelegateからあなたsignedIn変数を確認することができます。このように:基本的に何をする必要があると、単にあなたのCredentialStateクラス上のコードのこの部分を持っています。だから、単にAppDelegateであなたをできるファイル:私はこれは完全に働いたあなたの質問

関連する問題