ユーザー登録している場合はタイムラインへ遷移、ユーザー登録していない場合はサインイン画面に遷移というの実装する方法を調べていたのでメモ。
ViewcontrollerにStoryboard IDをつける
![Main_storyboard.png](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.amazonaws.com%2F0%2F55904%2F12ed3469-1f39-5178-8269-75e6e04afe83.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=f19879a1968e3fdbb993da39969e9fef)
今回はユーザーが登録をしていない場合はユーザー登録画面に遷移する
AppDelegate.swiftにコードを追加
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let currentuser:String? = "Username"
//ユーザーがいない場合サインイン画面に遷移
if (currentuser == nil){
//windowを生成
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
//Storyboardを指定
let storyboard = UIStoryboard(name: "Main", bundle: nil)
//Viewcontrollerを指定
let initialViewController = storyboard.instantiateViewControllerWithIdentifier("Signin")
//rootViewControllerに入れる
self.window?.rootViewController = initialViewController
//表示
self.window?.makeKeyAndVisible()
}else{
//ユーザーがいる場合Storyboardでチェックの入っているIs Initial View Controllerに遷移する
}
return true
}
以上です。
他にもこんな方法あるよというのがあれば是非教えて下さい!