Save 37% off PRO during our Black Friday Sale! »

The Great Swift Migration

The Great Swift Migration

Migrating 30,000 lines of code from Objective-C to Swift

9f33218af7ae5c04e102fcc3076f2f5c?s=128

yhkaplan

July 30, 2019
Tweet

Transcript

  1. The Great Swift Migration 1

  2. Self Intro 2

  3. — Name: Josh Kaplan — Company: GMO Pepabo — App:

    minne — Strengths: English — Hobbies: Collecting Xcode versions 3
  4. 30,000 lines of Obj-C 4

  5. Why? 5

  6. — Future proofing — Safety — Productivity with features like

    generics, etc — Security 6
  7. How? 7

  8. Modernize Objective-C 8

  9. @property (nonatomic, nonnull) NSArray<MICreator *> *creators; @property (nonatomic, nonnull) MICartPayment

    *payment; @property (nonatomic, nonnull) MIAPIClient *client; @property (nonatomic, nullable) MICoupon *coupon; 9
  10. Check nullability in current Swift code let num: Int? =

    nil "\(num)" // String interpolation produces a debug description for an optional value 10
  11. Choosing which areas to migrate — First, modernize models —

    Then, ViewControllers and ViewModels/Presenters — Work on feature/module basis — Avoid converting code that is then used in obj-c — Cells and smaller views can wait 11
  12. Details 12

  13. Steps 13

  14. 1. Move properties in m file to header and add

    annotations 2. Make Swift file and make extension 3. Migrate non-lifecyle methods and commit for each method 4. Make temporary method for lifecycle and IBAction method contents 5. Migrate lifecycle methods and properties 6. Update storyboard 14
  15. Points 15

  16. — Only minor refactoring — Writing tests first helps —

    Communicate with team to prevent conflicts — Things like major renaming should be in separate PRs to make review easier — Set goals and monitor progress with tools like tokei 16
  17. Bonus: Migrating to SwiftUI 17

  18. — Small components — Use Xcode Preview now — Fewer

    dependencies — Swift ! 18