1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Swift】ライブラリ Instantiate を使用した際のエラー "Fatal error: Unexpectedly found nil while unwrapping an Optional value"

Last updated at Posted at 2021-03-15

エラー

Storyboard+UIViewController.swift
    public extension StoryboardInstantiatable where Self: UIViewController {
        init(with dependency:Dependency) {
            let storyboard = (Self.self as StoryboardType.Type).storyboard
            switch Self.instantiateSource {
            case .initial:

                // ここで落ちた
                self = storyboard.instantiateInitialViewController() as! Self
            case .identifier(let identifier):

                self = storyboard.instantiateViewController(withIdentifier: identifier) as! Self
            }
            if self is ViewLoadBeforeInject {
                _ = self.view
            }
            self.inject(dependency)
        }
    }

解決策

Storyboardの Is Initial View Controller にチェックをする。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?