MihaelIsaev / UIKitPlus

🏰 Declarative UIKit with LivePreview for iOS9+ (best alternative to SwiftUI)
MIT License
596 stars 35 forks source link

Avoid launching main app if rendering previews #25

Open markst opened 2 years ago

markst commented 2 years ago

Rendering preview's can be optimised by checking XCODE_RUNNING_FOR_PREVIEWS environment variable

@AppBuilder override var body: AppBuilderContent {
  MainScene { .main }
  .mainScreen {
    // Avoid loading `ShowsListViewController` is rendering previews:
    if ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1" {
      return UIViewController()
    }
    return NavigationController(ShowsListViewController(viewModel: ShowsListViewModel()))
      .style(.transparent)
      .hideNavigationBar()
  }
}