GithubHelp home page GithubHelp logo

Comments (2)

AliSoftware avatar AliSoftware commented on June 22, 2024 3

Hi

Reusable is totally able to do this, and StoryboardSceneBased is indeed intended to be used exactly instantiate controllers designed in storyboards containing multiple scenes.

As explained in the README here (don't hesitate to click on the little black triangles to open the collapsed examples in that README btw), when you're using StoryboardSceneBased, the name of the class is used by default to determine the sceneIdentifier (and not the name of the *.storyboard file), so in order for iOS to know from which *.storyboard to extract that scene/controller, you'll need to explicitly provide a value for the sceneStoryboard property in each class you mark conforming to StoryboardSceneBased.

(StoryboardSceneBased is probably the only protocol in the Reusable library where not everything in the protocol has a default implementation, so this one is not really fully a "Mixin" per-se as you still have to provide that property explicitly)


class IntroViewController: StoryboardSceneBased {
  static let sceneStoryboard = UIStoryboard(name: "Intro", bundle: nil)
}
class SplashViewController: StoryboardSceneBased {
  static let sceneStoryboard = UIStoryboard(name: "Intro", bundle: nil)
}
class ViewController1: StoryboardSceneBased {
  static let sceneStoryboard = UIStoryboard(name: "Main", bundle: nil)
}
class ViewController2: StoryboardSceneBased {
  static let sceneStoryboard = UIStoryboard(name: "Main", bundle: nil)
}

PS: Note/Tip: to avoid repeating the string literals corresponding to the storyboard names and avoid making mistakes, I recommend to either:

  1. create namespaced constants for the UIStoryboard instances, ready to use them in each ViewController's static let sceneStoryboard implementation:
enum Storyboards {
  static let intro = UIStoryboard(name: "Intro", bundle: nil)
  static let main = UIStoryboard(name: "Main", bundle: nil)
}
class IntroViewController: StoryboardSceneBased {
  static let sceneStoryboard = Storyboards.intro
}
class SplashViewController: StoryboardSceneBased {
  static let sceneStoryboard = Storyboards.intro
}
  1. Or even better, use a tool like SwiftGen to auto-generate (and auto-maintain) those at build time (which actually also generates functions and constants to instantiate Storyboard-based ViewControllers in a type-safe way too, so that's an alternative solution to Reusable for that feature.

from reusable.

snowtema avatar snowtema commented on June 22, 2024

@AliSoftware Thanks a lot for the quick feedback!

from reusable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.