こんにちは、IOS プロジェクトに swinject を適用しようとしていますが、現在行き詰まっています..
アプリケーションに2つの部分があります
- ログイン部
- 主要部分
シナリオは、アプリケーションの開始時またはログインが成功したときにすでにログインしている場合は、メイン部分に移動する必要があり、それぞれにswinjectスコープがインスタンスを個別に管理する独自のストーリーボードがあることを願っています。
ログインが完了すると、メイン部分が注入されたインスタンスが新しく生成され、ログアウトが完了すると、LOGIN部分に戻り、メイン部分が注入されたインスタンスがなくなるはずです..
以下は私のView Controllerの構造です:
この指定により、以下のコードで MAIN ビューに移動しようとしていますが、エラーが発生し続けます。
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else {
return
}
// add these lines
let storyboard = UIStoryboard(name: "Main", bundle: nil)
// if user is logged in before
if let loggedUsername = UserDefaults.standard.string(forKey: "username") {
// instantiate the main tab bar controller and set it as root view controller
// using the storyboard identifier we set earlier
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainTabBarController = storyboard.instantiateViewController(identifier: "MainTabBarController")
window?.rootViewController = mainTabBarController
} else {
// if user isn't logged in
// instantiate the navigation controller and set it as root view controller
// using the storyboard identifier we set earlier
let loginNavController = storyboard.instantiateViewController(identifier: "LoginNavigationController")
window?.rootViewController = loginNavController
}
}
extension SwinjectStoryboard {
@objc class func setup() {
defaultContainer.autoregister(UserProvider.self, initializer: UserProvider.init).inObjectScope(.container)
defaultContainer.storyboardInitCompleted(HomeViewController.self) { resolver, controller in
controller.userProvider = resolver ~> UserProvider.self
}
}
}
Storyboard (<SwinjectStoryboard.SwinjectStoryboard: 0x600002304300>) doesn't contain a view controller with identifier 'MainTabBarController'
これを解決するにはどうすればいいですか??