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

MobiConf 2021 - SwiftUI.View: Codable

MobiConf 2021 - SwiftUI.View: Codable

Florian Harr

October 08, 2021
Tweet

More Decks by Florian Harr

Other Decks in Programming

Transcript

  1. Transforming SwiftUI to JSON (and Vice-Versa) 
 for a fully

    backend driven UI MobiConf Summit 2021 - Florian Harr - Betterment “When you need that extra bit of f lexibility”
  2. Hi👋 • i(Phone)OS since 2008/2009 • Remote @ Betterment •

    Hates to work on “Move the UIButton 5px left” stories • DMs open: @CaffeineFlo • Obvious Dog Fanatic! I’m Florian!
  3. • Investment, IRA and 401(k) Provider with best-in-class automated investing

    strategies (and human advisors!) • Strong engineering team and culture with > 100 Engineers across the US • Of f ices in NY, Philly, Denver • Remote positions available • We’re hiring (https://www.betterment.com/careers/current-openings/)
  4. Transforming SwiftUI to JSON (and Vice-Versa) 
 for a fully

    backend driven UI “When you need that extra bit of f lexibility” Entertaining Informative FUN
  5. +

  6. +

  7. Parameterized SwiftUI Views • Initializes Views from backing Data Structure

    (e.g. Codable JSON Models) • Works nicely with screens that don’t have many layout variations • Clear implementation experience
  8. Parameterized SwiftUI Views Follow Up Resources • Con f iguring

    SwiftUI Views - SwiftBySundell • How to create and compose custom views • Getting started with UIKit in SwiftUI and vice versa
  9. • Evolution to parameterized SwiftUI Views • Compose different screens

    from sets of shipped Views remotely • Can be as “dynamic” as consuming another API at runtime to describe full screens HackingWithSwift - iDine Dynamic Screens with shipped Views
  10. Dynamic Screens with shipped Views Follow Up Resources • Optional

    SwiftUI Views - SwiftBySundell • 5 Steps to Better SwiftUI Views - HackingWithSwift • Managing scenes in SwiftUI - Swift with Majid
  11. Wouldn’t you like to 
 update your UI 
 without

    releasing 
 a new version? … and rather watch football instead?
  12. Would you rather 
 spend your time 
 on actual

    features 
 that you 
 interviewed for?
  13. JSON Deserializer/ 
 ViewFactory Decoded 
 SwiftUI View API Server

    User Input Requests Sends Receives Shows Page/ Device Type/ Version etc.
  14. List Stack SwiftUI.View: Codable - 
 Transforming SwiftUI to JSON

    (and vice-versa) for a fully backend driven UI
  15. • Encode what you need • Encodable extensions for standard

    views • Grab the JSON output form the console • What You See Is What You Get (WYSIWYG) Editor for more advanced scenarios
  16. Re-imagine Screens On-The-Fly Server Side Rendering isn’t a brand-new technology

    and has been used on (reactive) web for a long time. There are many use-cases and bene f its where this architecture enables a f lexibility that is hard to replicate otherwise. It comes with trade-offs though and SwiftUI (in it’s current state) requires a good bit of boilerplate code to make it work.
  17. • Excellent opportunity for mostly “static” content to be represented

    natively on mobile • WebViews have their own challenges and often lacking accessibility that SwiftUI/Jetpack compose overcome easily • Use-Cases: • Consumable Media (e.g. News) • Account/User Pro f iles with many edge-cases • Forms
  18. • Versioning will eventually add another layer of complexity on

    top • “Actions” or function calls can be complex and dangerous • Technologies often solve speci f ic problems 
 -> double check your use-cases