Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Prepping For A SwiftUI Future

Prepping For A SwiftUI Future

Many of us are excited to adopt SwiftUI in our production apps next year. We might be working on side projects to wrap our heads around this new paradigm. However, at work the situation is more complex. I will show you how to architect your current app for a smoother migration and include real world examples of UIKit/SwiftUI interoperability. You will leave able to lead crucial conversations with your team about what we can do now for a successful migration next year.

mathonsunday

May 18, 2020
Tweet

More Decks by mathonsunday

Other Decks in Programming

Transcript

  1. Flux Missing features Functional reactive programming MVVM Combine Testing Declarative

    Black box Less code to write Better performance App architecture SwiftUI Fun Composable Architecture Interoperability Missing documentation Collaboration with designers
  2. What App Architecture Is Best For SwiftUI? • MVVM •

    Flux • The Composable Architecture
  3. Animal Crossing Creators • Creators post IDs online that you

    use to download outfits • There’s no way to save these IDs in the game • Animal Crossing Creators allows you to save your favorite creators
  4. Why Use MVVM? • The “default” choice for SwiftUI •

    Many UIKit apps already use this successfully
  5. Why Use Flux? • Small amount of code needed •

    3rd party libraries for it are lightweight
  6. Why Use Composable Architecture? • Inspired by Flux, but more

    opinionated and heavyweight • Open source library with great documentation and examples • Example apps covering many domains • Videos showing thought process
  7. A Pragmatic Approach • Don’t need a big rewrite of

    existing app • Take advantage of the faster development speed of SwiftUI in new projects • Need to master the art of interoperability with UIKit
  8. public struct LabelRepresentation: UIViewRepresentable { var textColor: UIColor var font:

    UIFont var text: String public func makeUIView(context: UIViewRepresentableContext) -> Label { let label = Label() label.textColor = textColor label.font = font return label } public func updateUIView(_ uiView: Label, context: UIViewRepresentableContext) { uiView.text = text } }
  9. public struct LabelRepresentation: UIViewRepresentable { var textColor: UIColor var font:

    UIFont var text: String public func makeUIView(context: UIViewRepresentableContext) -> Label { let label = Label() label.textColor = textColor label.font = font return label } public func updateUIView(_ uiView: Label, context: UIViewRepresentableContext) { uiView.text = text } }
  10. public struct LabelRepresentation: UIViewRepresentable { var textColor: UIColor var font:

    UIFont var text: String public func makeUIView(context: UIViewRepresentableContext) -> Label { let label = Label() label.textColor = textColor label.font = font return label } public func updateUIView(_ uiView: Label, context: UIViewRepresentableContext) { uiView.text = text } }
  11. public struct LabelRepresentation: UIViewRepresentable { var textColor: UIColor var font:

    UIFont var text: String public func makeUIView(context: UIViewRepresentableContext) -> Label { let label = Label() label.textColor = textColor label.font = font return label } public func updateUIView(_ uiView: Label, context: UIViewRepresentableContext) { uiView.text = text } }
  12. public struct PageIndicatorView: View { @ObservedObject var model: PageIndicatorModel public

    var body: some View { LabelRepresentation(textColor: .white, font: .compassSansMedium(12), text: model.text) } }
  13. imageCarouselView.didScrollHandler.subscribe(onNext: { [weak self] _ in guard self?.images.count ?? 0

    > 1 else { return } self?.pageIndicatorView.rootView.model.index = (self?.currentPageIndex ?? 0) + 1 self?.pageIndicatorView.rootView.model.count = self?.images.count ?? 0 })
  14. Summary • Decide now if you want to adopt a

    new app architecture • When you can, write all new code in SwiftUI • Adopt SwiftUI and Combine together unless you have a great reason to not use Combine • Do interoperability spikes in your production app