34
Migrating to Swift3 @kandelVijaya

How we migrated Zalando app to Swift3?

Embed Size (px)

Citation preview

Page 1: How we migrated Zalando app to Swift3?

Migrating to Swift3@kandelVijaya

Page 2: How we migrated Zalando app to Swift3?

Intro to Japanese

• 私の名前はビゼです。

• My name is Bj.

Page 3: How we migrated Zalando app to Swift3?

Readability matters.Obj-C [string writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error];

<= Swift2.3 "SomeLongText".writeToFile(path, atomically: false, encoding: NSUTF8StringEncoding, error: nil)

Swift3 try! "SomeLongText".write(to: path, atomically: true, encoding: String.Encoding.utf8)

Swift3 try "SomeLongText".write(to: path, atomically: true, encoding: .utf8)

Page 4: How we migrated Zalando app to Swift3?

• Change or it will.

• Different point of view makes you analyse options better

Page 5: How we migrated Zalando app to Swift3?

Key facts at Zalando• 12 iOS engineers

• 1 repository

• 5 years and counting

• Around 1,00,000 Lines of “OUR” Code

• 51% Swift

• 48% Obj-C

Page 6: How we migrated Zalando app to Swift3?

1 Migrator

Page 7: How we migrated Zalando app to Swift3?
Page 8: How we migrated Zalando app to Swift3?

Thousands of Fixes

Page 9: How we migrated Zalando app to Swift3?

Branch

Develop*

Page 10: How we migrated Zalando app to Swift3?

Branch

Develop*

swift-3-test

Page 11: How we migrated Zalando app to Swift3?

Branch

Develop*

swift-3-test

Page 12: How we migrated Zalando app to Swift3?

FFR

• Get more error (~ 170). Fix

• Fix

• Run!

Page 13: How we migrated Zalando app to Swift3?

Fixes

• Trivial changes on 95%

• 5% required cognitive effort

Page 14: How we migrated Zalando app to Swift3?

Comment

• For non trivial fixes, we placed comments

Page 15: How we migrated Zalando app to Swift3?

Branch

Develop*

swift-3-test

Page 16: How we migrated Zalando app to Swift3?

30+ FFRDevelop*

swift-3-test

Page 17: How we migrated Zalando app to Swift3?

FFR again

Develop* swift-3-test

Page 18: How we migrated Zalando app to Swift3?

Features

Develop* swift-3-test

F1 F2

Page 19: How we migrated Zalando app to Swift3?

Develop*

swift-3-testF1

F2

Page 20: How we migrated Zalando app to Swift3?

Fixing More• Fixing Pods / Dependencies

• Removed TimePiece, Hamcrest

• Migrated ones that didn’t have Swift3 branch yet

• Fixing Unit tests, UI tests

• Make it run!

Page 21: How we migrated Zalando app to Swift3?

Do we merge to develop?

• 2 days for entire team to fix the comments

• Do regression test and verify consistency

• Bug bash

Page 22: How we migrated Zalando app to Swift3?

Getting back

Develop* swift-3-testF1F2

Page 23: How we migrated Zalando app to Swift3?

Feature Progress

Develop* swift-3-testF1

F2

Page 24: How we migrated Zalando app to Swift3?

Develop*

swift-3-test

F1

F2

Page 25: How we migrated Zalando app to Swift3?

Done!

• But wait!!

Page 26: How we migrated Zalando app to Swift3?

How long?

• Almost a month.

• 1 week vacation

Page 27: How we migrated Zalando app to Swift3?

Most occurred cases

• [AnyObject: NSObject] —> [AnyHashable: Any]

• Dropping NS prefix

• Annotating closure with @escaping

• Type casting

Page 28: How we migrated Zalando app to Swift3?

• Parameter renaming. Not called delegates because of nearly matching signature ie. TableViewDelegate

Page 29: How we migrated Zalando app to Swift3?

• Parameter renaming. Not called delegates because of nearly matching signature ie. TableViewDelegate

Page 30: How we migrated Zalando app to Swift3?

• many IBAction didn’t work (when manually merging Swift2.3 to swift3). ie. merging later on.

• Private to fileprivate, its everywhere

• public to open everywhere, we didnt wanted it to be that way

Page 31: How we migrated Zalando app to Swift3?

New introduction

• fileprivate

• open

• parameter naming

• String! as Optional

Page 32: How we migrated Zalando app to Swift3?

Improvements

• Removal of C style for loop

• Removal of ++ and - - operator

• default for closure to @noescape

• More on the change-set

Page 33: How we migrated Zalando app to Swift3?

Interesting occurrences

• Method signature nearly matches

• @discardableResult func …. _ = nextResponder.perform(handler, with: actionInfo) _ = navigationController?.popViewController(animated: true)

• 969 warnings. Mostly from unannotated Obj-C API —

Page 34: How we migrated Zalando app to Swift3?

• 私の 名前は ビゼ です。

• My name is Bj.

• @kandelvijaya

• AnyQuestions?