65
1 Swift’s migration. The true Story Miguel Olmedo Camacho @molmedoc Enrique Fau de Casa- Juana @kikefau

Swift migration. the true history

Embed Size (px)

Citation preview

Page 1: Swift migration. the true history

1

Swift’s migration. The true Story

Miguel Olmedo Camacho@molmedoc

Enrique Fau de Casa-Juana@kikefau

Page 2: Swift migration. the true history

2

Page 3: Swift migration. the true history

3

Motivaciones

Page 4: Swift migration. the true history

4

Motivaciones

Page 5: Swift migration. the true history

5

¿Por qué?

● Nuevo lenguaje● Sintaxis moderna● Más rápido● Fuertemente tipado● Genéricos ● Enfoque funcional● Closures VS Blocks● Refactor (Legacy code)

Motivaciones

Page 6: Swift migration. the true history

6

Punto de partida

Page 7: Swift migration. the true history

7

● Aplicación nativa (universal)● iOS >= 6● ≃ 1.000 ficheros● ≃ 140.000 líneas de código● 12 bibliotecas de terceros (pods)● Poco modularizada● Deuda técnica

Punto de partida

Page 8: Swift migration. the true history

8

El Camino

Page 9: Swift migration. the true history

9

Estrategia de migración

Page 10: Swift migration. the true history

10

Estrategia de migración

● Migración incremental● No congelamos nuevos desarrollos● Nuevos desarrollos en Swift● Pair programming - Code review● Tareas de deuda técnica● Refactor cuando sea necesario● Pods homólogos en Swift

Page 11: Swift migration. the true history

11

El comienzo

Page 12: Swift migration. the true history

12

● Creamos nuestro primer fichero en Swift!● idealista-Bridging-Header.h

o Clases de Objc que necesitan visibilidad desde Swift

● idealista-Swift.h (compilación)o XCode completa idealista-Swift con clases

de Swift que necesitan visibilidad desde Objc

El comienzo

Page 13: Swift migration. the true history

13

Primeros problemas

Page 14: Swift migration. the true history

14

● Comunicación Objc - Swift (IUO!)● Crashes en tiempo de ejecución● Dependencias Objc - Swift (Bridging header)● El target de test incluye todos los ficheros● If - let anidados● Sin cláusula where● XCode...

Primeros problemas (Swift 1)

Page 15: Swift migration. the true history

15

Primeros problemas

Page 16: Swift migration. the true history

16

Siguientes pasos: Xcode 6.3

Page 17: Swift migration. the true history

17

● Nulabilidad desde Objc● 40% del proyecto en Swift● VIPER● Estructuras para el modelo● Enumerados para el View - Model● Aumento del “code coverage”● Aumento “crash free users”● Aumento de tiempos de compilación

Siguientes pasos (XCode 6.3)

Page 18: Swift migration. the true history

18

Siguientes pasos (XCode 6.3)

Page 19: Swift migration. the true history

19

Xcode 7 - Swift 2

Page 20: Swift migration. the true history

20

● El drama, iOS 7o Crash en genéricoso Imposibilidad de usar Pods en Swifto Dejamos de dar soporte a iOS 7

● Mejoraso Testable importo Guardo If - let múltiples anidadoso Cláusula where

XCode 7 - Swift 2

Page 21: Swift migration. the true history

21

Xcode 8 - Swift 3

Page 22: Swift migration. the true history

22

● Proyecto 99,9% en Swift● Migración automática mis co**nes● Cambios en las firmas de los métodos● Enumerados en minúsculas● Comparar opcionales (Crash en runtime)● Nuevos warnings● Nuevos y divertidos troleos...

Swift 3 (XCode 8 - Swift 3)

Page 23: Swift migration. the true history

23

Swift 3 (XCode 8 - Swift 3)

Page 24: Swift migration. the true history

24

Page 25: Swift migration. the true history

25

Estructuras / Enumerados

Page 26: Swift migration. the true history

26

Estructuras

● Inmutabilidado Da seguridad

● Paso por valor vs paso por referenciao Cada caso es distinto

● Hay que acostumbrarse a usarloo A veces genera más problemas que

soluciones

Estructuras / Enumerados

Page 27: Swift migration. the true history

27

Enumerados

● No solo valen para representar valores disjuntoso Pueden tener lógica propia

● Valores asociados● Muchos usos

o View models, remote config, proveedores de login...

Estructuras / Enumerados

Page 28: Swift migration. the true history

28

Page 29: Swift migration. the true history

29

Page 30: Swift migration. the true history

30

Page 31: Swift migration. the true history

31

Blocks vs Closures

Page 32: Swift migration. the true history

32

● Sintaxis poco intuitiva

Bloques

Blocks vs Closures

Page 33: Swift migration. the true history

33

Bloques

Blocks vs Closures

http://fuckingblocksyntax.com/

Page 34: Swift migration. the true history

34

● Sintaxis poco intuitiva● Poco extendido su uso● En tareas asíncronas, se usan más los

delegados que los bloques

Bloques

Blocks vs Closures

Page 35: Swift migration. the true history

35

● Sintaxis mucho más natural, como si declarases métodos

Closures

Blocks vs Closures

Page 36: Swift migration. the true history

36

Bloques

Blocks vs Closures

http://fuckingclosuresyntax.com/

Page 37: Swift migration. the true history

37

● Sintaxis más natural● Trailing closure● Parámetros / Return implícitos● Mayor uso de closures vs delegates● Typealias para dar semántica● Cuidado con los ciclos de memoria

Closures

Blocks vs Closures

Page 38: Swift migration. the true history

38

Page 39: Swift migration. the true history

39

Page 40: Swift migration. the true history

40

Page 41: Swift migration. the true history

41

Page 42: Swift migration. the true history

42

Page 43: Swift migration. the true history

43

Page 44: Swift migration. the true history

44

Page 45: Swift migration. the true history

45

VIPER

Page 46: Swift migration. the true history

46

Definición

VIPER

Page 47: Swift migration. the true history

47

Frameworks dinámicos

Page 48: Swift migration. the true history

48

● Nos sirve para desacoplar la aplicacióno Módulo de servicios, gestión de

localización del usuario, core spotlight...● Reutilización de código

o Aplicación /Apple Watch / ¿tv OS?● Menos conflictos durante el desarrollo● Mejor separación de responsabilidades

Frameworks dinámicos

Frameworks dinámicos

Page 49: Swift migration. the true history

49

Programación orientada a protocolos

Page 50: Swift migration. the true history

50

Ejemplo

Programación orientada a protocolos

Page 51: Swift migration. the true history

51

Ejemplo

Programación orientada a protocolos

Page 52: Swift migration. the true history

52

Page 53: Swift migration. the true history

53

Page 54: Swift migration. the true history

54

Page 55: Swift migration. the true history

55

Page 56: Swift migration. the true history

56

Page 57: Swift migration. the true history

57

Page 58: Swift migration. the true history

58

Consejos

Page 59: Swift migration. the true history

59

● Poco a poco, sin prisa● Nuevas funcionalidades en Swift

o Sus test correspondientes también● Mejor pasar primero a Swift el código antiguo

y crear deuda técnica que refactorizar el código mientras se está migrando

● Apoyarse en los test● Quitar soporte iOS 7

Consejos

Page 60: Swift migration. the true history

60

Consejos (tiempos de compilación)

Derived data en RAMPods y workspace al GitPods privadosSwift Whole Module

OptimizationXfrontend -debug-time-

function-bodies

Page 61: Swift migration. the true history

61

Libros y enlaces

Page 62: Swift migration. the true history

62

Para aprender Swift● https://itunes.apple.com/es/book/swift-programming-language/id881256329?mt=11● https://itunes.apple.com/es/book/using-swift-cocoa-objective/id888894773?mt=11● https://itunes.apple.com/es/course/developing-ios-9-apps-swift/id1104579961?l=en

Swift avanzado● https://www.objc.io/books/advanced-swift/

Programación funcional con Swift● https://www.objc.io/books/functional-swift/● https://www.raywenderlich.com/114456/introduction-functional-programming-swift● https://realm.io/news/altconf-chris-eidhof-functional-programming-in-swift/

Protocol oriented programming● https://developer.apple.com/videos/play/wwdc2015/408/● https://developer.apple.com/videos/play/wwdc2016/419/● https://realm.io/news/appbuilders-natasha-muraschev-practical-protocol-oriented-programmi

ng/● https://realm.io/news/doios-natasha-murashev-protocol-oriented-mvvm/● http://krakendev.io/blog/subclassing-can-suck-and-heres-why● https://speakerdeck.com/jessesquires/pushing-the-limits-of-protocol-oriented-programming● https://www.raywenderlich.com/109156/introducing-protocol-oriented-programming-in-swift-

2● https://www.natashatherobot.com/protocol-oriented-views-in-swift/● https://www.natashatherobot.com/protocol-oriented-networking-in-swift/

Libros y enlaces

Page 63: Swift migration. the true history

63

Nuevas funcionalidades en Swift 3● https://github.com/apple/swift-evolution/blob/master/releases/swift-3_0.md

Bugs● http://stackoverflow.com/questions/28476030/xcode-keeps-building-storyboard-after-each-k

eystroke● https://forums.developer.apple.com/thread/43445● https://forums.developer.apple.com/thread/62737

VIPER● https://www.objc.io/issues/13-architecture/viper/● https://github.com/mutualmobile/VIPER-SWIFT

Value Types● https://realm.io/news/andy-matuschak-controlling-complexity/● https://www.objc.io/issues/16-swift/swift-classes-vs-structs/● https://www.raywenderlich.com/112027/reference-value-types-in-swift-part-1● https://developer.apple.com/swift/blog/?id=10

Page 64: Swift migration. the true history

64

Gracias!!

Miguel Olmedo Camacho@molmedoc

Enrique Fau de Casa-Juana@kikefau

Page 65: Swift migration. the true history

65

¿Preguntas?

Miguel Olmedo Camacho@molmedoc

Enrique Fau de Casa-Juana@kikefau