Git Product home page Git Product logo

Comments (9)

esttorhe avatar esttorhe commented on May 17, 2024

I was thinking in generating a different protocol aside from StoryboardScene; perhaps StoryboardSegue and generate the segues in there.

from swiftgen.

AliSoftware avatar AliSoftware commented on May 17, 2024

Yeah, I like that. But what about generated enums then (I'm thinking for a nice API at the call site here)?

Would there be a UIStoryboard.Name.Wizzard.Scene enum for the scenes and a UIStoryboard.Name.Wizzard.Segue for the segues? (That starts to be ridiculously long/deep namespacing… UIStoryboard.Name.Wizzard.Scene.CGU.viewController() pfiew!)

Or maybe UIStoryboard.Scenes.Wizzard and UIStoryboard.Segues.Wizzard enums instead?


I'm thinking of what it would look like at the call site. So far I think something like this could be nice:

let vc1 = UIStoryboard.Scenes.Wizzard.CGU.viewController() // as a UIViewController
let vc2 = UIStoryboard.Scenes.Wizzard.viewController(.CGU) // same, just an alternative syntax
let vc3 = UIStoryboard.Scenes.Wizzard.passwordViewController() // typed as a XXPasswordViewController

let segue1 = UIStoryboard.Segues.Wizzard.Test.segue() // as a UIStoryboardSegue
let segue2 = UIStoryboard.Segues.Wizzard.segue(.Test) // same — alternative syntax
let segue3 = UIStoryboard.Segues.Wizzard.testSegue() // typed as a CustomStoryboardSegue

Note: The opposite would look more logical (in a hierarchical POV), like UIStoryboard.Wizzard.Scenes.CGU.viewController() and UIStoryboard.Wizzard.Segues.testSegue(), but that would clobber the UIStoryboard namespace, which I want to avoid (and adding an extra scope of UIStoryboard.Name.Wizzard.Scenes.CGU.viewController() seems way to much), whereas with the above solution, we only add 2 symbols at the root of the UIStoryboard namespace, whatever the number of storyboards and segues we have in the project.

from swiftgen.

esttorhe avatar esttorhe commented on May 17, 2024

I think UIStoryboard.Segue.<Name> and UIStoryboard.Scene.<Name> makes the most sense to me.

I don't know if there's a need for helper methods to access the segues other than just having the names of the available segue on a specific Storyboard though.

What do you think?

from swiftgen.

AliSoftware avatar AliSoftware commented on May 17, 2024

Yeah only having an enum UIStoryboard.Segue.Wizzard with the case Test and case OtherSegueName etc, is probably enough, the UIStoryboard.Segue.Wizzard.testSegue() helper method are probably useless for segues as you rarely use custom subclasses for them, do you?

from swiftgen.

esttorhe avatar esttorhe commented on May 17, 2024

I rarely subclass them and even if I did there's not need to create one like that

from swiftgen.

AliSoftware avatar AliSoftware commented on May 17, 2024

So to be clear, it would probably look like this, right?

extension UIStoryboard {
  enum Scene {
    /* what is currently generated in the UIStoryboard.Name enum by the current code, like: */
    enum Wizzard : String, StoryboardScene {
      static let storyboardName = "Wizzard"

      case CreateAccount = "CreateAccount"
      static var createAccountViewController : CreateAccViewController {
        return Wizzard.CreateAccount.viewController() as! CreateAccViewController
      }
      ...
    }
    enum Message : String, StoryboardScene {
      ...
    }
  }

  enum Segue {
    enum Wizzard : String, StoryboardSegue {
      case Segue1OfTheWizzardStoryboard = "Segue1"
      case Segue2OfTheWizzardStoryboard = "Segue2"
    }
    enum Message : String, StoryboardSegue {
      case Segue1OfTheMessageStoryboard = "Segue1"
    }
  }
}

If so, I actually wonder what the protocol StoryboardSegue would contain? Maybe only a static func segue(identifier: Self) to build an UIStoryboardSegue instance from that enum, but even for that I wonder if that's even necessary, do you really instantiate UIStoryboardSegue instances in real life? You generally only switch on their identifier in prepareForSegue() but not much create them yourself, so…

from swiftgen.

esttorhe avatar esttorhe commented on May 17, 2024

Yeah; I don't think that's segue(identifier: is needed.

Exactly; I usually only need to check the segue id on the prepareForSegue()

from swiftgen.

AliSoftware avatar AliSoftware commented on May 17, 2024

Ok great! So I'd say forget about that StoryboardSegue protocol for now ;)

from swiftgen.

AliSoftware avatar AliSoftware commented on May 17, 2024
override func prepareForSegue(_ segue: UIStoryboardSegue, sender sender: AnyObject?) {
  switch UIStoryboard.Segue.Wizzard(rawValue: segue.identifier)! {
    case .Segue1OfTheWizzardStoryboard
      …
    case .Segue2OfTheWizzardStoryboard
      …
  }
}

That looks nice from the call site :)

from swiftgen.

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.