Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

From Objective-C to Swift

A brief summary of eight Swift features that have, in particular, affected our lives as iOS developers.

I gave this talk in a ESL-Inaka Get Together event on April 30th, 2016. The talk was mostly spoken, the slides themselves only show a summary of all the items I spoke about.

  • Login to see the comments

  • Be the first to like this

From Objective-C to Swift

  1. 1. www.erlang-solutions.com ERLANG SOLUTIONS GET2GETHER TIGRE 2016
  2. 2. www.erlang-solutions.com FROM OBJECTIVE-C TO SWIFT
  3. 3. www.erlang-solutions.com HELLO! Pablo Villar pablo@inakanetworks.com @pablolvillar www.erlang-solutions.com www.inaka.net
  4. 4. www.erlang-solutions.com EXPERIENCES WE'VE LEARNED FROM SOME SWIFT FEATURES How has this new language affected our developer lives?
  5. 5. www.erlang-solutions.com 1. SWIFT IS STATICALLY TYPED
  6. 6. www.erlang-solutions.com SWIFT IS STATICALLY TYPED ▸ Type checking at compile-time ▸ We can catch mistakes at earlier stages ▸ Less runtime crashes ▸ Less magic, more knowledge
  7. 7. www.erlang-solutions.com Swift (Static Types) More restrictions when writing code. It's harder to get along with the compiler and be good friends, but that's a good thing. SWIFT IS STATICALLY TYPED OBJ-C (Dynamic Types) More freedom when writing code. However, this magic comes with the high cost of experiencing undesired behavior or potential crashes at runtime.
  8. 8. www.erlang-solutions.com 2. SWIFT HAS GOT OPTIONALS
  9. 9. www.erlang-solutions.com Swift You need to define specific paths for null vs non-null scenarios. You are not allowed to perform operations on a nil variable that's supposed not to be nil. SWIFT HAS GOT OPTIONALS OBJ-C You can call a method with a pointer variable that is nil, and nothing will happen. This no-op leads to unpredictable behavior.
  10. 10. www.erlang-solutions.com SWIFT HAS GOT OPTIONALS ▸ We are forced to deal with null types ▸ Our code becomes safer ▸ We get used not to forget the error paths ▸ We code with intention ▸ Sometimes, we discover hidden scenarios that haven't been defined in the specs yet. ▹ In consequence, we become more proactive in the development loop.
  11. 11. www.erlang-solutions.com 3. SWIFT TAKES A FUNCTIONAL APPROACH
  12. 12. www.erlang-solutions.com SWIFT TAKES A FUNCTIONAL APPROACH ▸ Enums on steroids ▸ Pattern matching ▸ Functions as first-class citizens ▹ Perfect fit for completion closures ▹ Higher order functions ▹ Map, filter, reduce ▸ The importance of: ▹ Immutability ▹ Value types ▹ Avoiding state ▸ Testable code as a consequence
  13. 13. www.erlang-solutions.com 4. SWIFT IS A PROTOCOL ORIENTED PROGRAMMING LANGUAGE
  14. 14. www.erlang-solutions.com SWIFT IS A PROTOCOL ORIENTED PROGRAMMING LANGUAGE ▸ Protocols in Swift have been given more features and are more encouraged ▸ Favor composition over inheritance ▸ Code is more extensible and flexible ▸ In combination with generics, they become way powerful
  15. 15. www.erlang-solutions.com USING PLAIN INHERITANCE
  16. 16. www.erlang-solutions.com USING PROTOCOL COMPOSITION
  17. 17. www.erlang-solutions.com 5. SWIFT HAS GOT GENERICS
  18. 18. www.erlang-solutions.com SWIFT HAS GOT GENERICS ▸ With generics, we can solve general problems writing less code... ▸ This concept encourages us to: ▹ Think of more layers of abstraction ▹ Solve problems in a generic way ▹ Find out common code architecture patterns in our apps and generalize them ▹ Write more open-source code
  19. 19. www.erlang-solutions.com 6. MODELS IN SWIFT ARE MORE POWERFUL
  20. 20. www.erlang-solutions.com MODELS IN SWIFT ARE MORE POWERFUL Swift You can define classes, structs and enums. They all have the same power at their core. OBJ-C You can define classes, structs and enums. While classes is the only one that has real power, structs and enums are vastly poor in comparison (they come from C).
  21. 21. www.erlang-solutions.com ▸ Structs and Enums have been leveled up ▸ We started to use them much more ▸ We have learned: ▹ The value of value types ▹ How to avoid side effects ▹ Pattern-matching ▹ Why the if clause can be avoided ▹ The importance of immutability MODELS IN SWIFT ARE MORE POWERFUL
  22. 22. www.erlang-solutions.com 7. SWIFT IS EASIER TO READ
  23. 23. www.erlang-solutions.com SWIFT IS EASIER TO READ, WRITE, MAINTAIN, ETC... ▸ Cleaner syntax ▸ Better expressiveness ▸ Much more friendly ▸ More similar to modern languages ▸ Encourages more devs to learn it ▹ Community is getting way bigger bye-bye-brackets.png
  24. 24. www.erlang-solutions.com 8. SWIFT IS OPEN SOURCE
  25. 25. www.erlang-solutions.com SWIFT IS OPEN SOURCE! ▸ Language is evolving around the community ▹ Proposals are encouraged ▹ So are discussions ▹ Much more documentation ▹ More people getting involved ▸ Bring Swift to other platforms ▹ Linux ▹ Android ▹ Windows
  26. 26. www.erlang-solutions.com WRAPPING UP...
  27. 27. www.erlang-solutions.com IN CONCLUSION Swift has changed the way we program and how we think of programming. We've got less error prone code and more solid codebases. We are also learning from other paradigms, which makes us more flexible and open-minded.
  28. 28. www.erlang-solutions.com THANK YOU! Any questions? pablo@inakanetworks.com @pablolvillar www.erlang-solutions.com www.inaka.net

×