Swift 3 Compatible

I’ve been making a lot of improvements to the Clean Swift Xcode Templates, but it’s taking a lot longer than I anticipated. In the meantime, I’ve upgraded the templates to be compatible with the latest Xcode 8 and Swift 3. You can now get back to work with your latest toolchain, without having to manually fix the generated files. Enjoy!

You can download the updated templates using the same link in your previous email.

I’ll update the templates again when the new features are ready to ship. Stay tuned.

9 responses

  1. In the Swift 3 version of your templates, there’s some errors when you create unit tests. You forgot to change NSBundle to Bundle and NSRunLoop, RunLoop and NSDate to Date in the ViewControllerTests.

    need to be changed to:

      • Regarding your template update, when I test with Bundle.main, the test crash because of a cast error:

        Could not cast value of type ‘TestCleanSwift.ListOrdersViewController’ (0x107b4bf98) to ‘TestCleanSwiftTests.ListOrdersViewController’ (0x114cd25b8)

        It’s working fine with Bundle(for: type(of: self))

        • This is working for me:

          func setupListOrdersViewController() {
          let bundle = Bundle.main
          let storyboard = UIStoryboard(name: “Main”, bundle: bundle)
          sut = storyboard.instantiateViewController(withIdentifier: “ListOrdersViewController”) as! ListOrdersViewController
          }

          func loadView() {
          window.addSubview(sut.view)
          RunLoop.current.run(until: Date())
          }

  2. Hey Raymond,
    What if I need to share some functionality amongst several scenes? How would you handle that case? E.g. I have a footer, which displays some value. That footer takes place on 4 screens. I wouldn’t want to copy paste the code to all the scenes where I need that functionality.

    • Hi Andrey,

      What about creating a reusable UIView subclass to contain all your display logic in one place? And then supply it with the view models it needs to display your values? Finally, bubble up any user actions up to the view controllers and interactors to handle the business logic?

      This way, different scenes can respond differently to user button taps and whatnot. But your display logic is DRY.

      • Who will responsible for supplying the view with view models in this case? If I’ll need to create several similar VIP cycles, then DRY principle won’t be met.

        • Hi Andrey,

          Your view controllers will supply the views with the view models they receive from the presenters. The VIP cycle is unique to each scene. Don’t mix them. You can have many use cases passing through the VIP cycle. Don’t over-DRY things. If you have complex business logic in an interactor, you can extract it to a worker which can be shared between scenes.

          • Still, this doesn’t look optimal. I have to define exact the same models in SceneModels and write exact the same method calls for all the scenes where I want to place the shared view. I’ll have to write exact same unit tests for that functionality for all the scenes. If I want to change the behaviour, I have to edit all models/interactors/presenters/unit tests and view controllers. There must be a better way, right?
            The only option coming to my mind is to have embedded controller.

Leave a Reply

Your email address will not be published. Required fields are marked *