$30 off During Our Annual Pro Sale. View Details »

The Great Swift Migration

The Great Swift Migration

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

yhkaplan

July 30, 2019
Tweet

More Decks by yhkaplan

Other Decks in Programming

Transcript

  1. The Great Swift Migration
    1

    View Slide

  2. Self Intro
    2

    View Slide

  3. — Name: Josh Kaplan
    — Company: GMO Pepabo
    — App: minne
    — Strengths: English
    — Hobbies: Collecting Xcode versions
    3

    View Slide

  4. 30,000 lines of Obj-C
    4

    View Slide

  5. Why?
    5

    View Slide

  6. — Future proofing
    — Safety
    — Productivity with features like generics, etc
    — Security
    6

    View Slide

  7. How?
    7

    View Slide

  8. Modernize Objective-C
    8

    View Slide

  9. @property (nonatomic, nonnull) NSArray *creators;
    @property (nonatomic, nonnull) MICartPayment *payment;
    @property (nonatomic, nonnull) MIAPIClient *client;
    @property (nonatomic, nullable) MICoupon *coupon;
    9

    View Slide

  10. Check nullability in current Swift code
    let num: Int? = nil
    "\(num)" // String interpolation produces a debug description for an optional value
    10

    View Slide

  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

    View Slide

  12. Details
    12

    View Slide

  13. Steps
    13

    View Slide

  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

    View Slide

  15. Points
    15

    View Slide

  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

    View Slide

  17. Bonus: Migrating to SwiftUI
    17

    View Slide

  18. — Small components
    — Use Xcode Preview now
    — Fewer dependencies
    — Swift
    !
    18

    View Slide