Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Optionals, Protocols and Extensions - Swift by Example - SoCal Code Camp '16

November 26, 2016

Optionals, Protocols and Extensions - Swift by Example - SoCal Code Camp '16

Whether you are working with Swift as your first language or if you are coming from another language, Swift has some quirks setting it apart from other languages.

We will explore some of the reasonings, implementations and usages of these elements in the language through practical examples. Some of the Swift concepts we will be looking at are Optionals, Protocols and Extensions.


November 26, 2016

More Decks by kickinbahk

Other Decks in Programming


  1. Optionals, Protocols and Extensions Swift by Example @kickinbahk Josiah Mory

  2. Swift from a High Level

  3. Aims to be Objective-C without the C

  4. Swift is Type Safe

  5. Optionals

  6. Provide compile-time check that would prevent some common programming errors

    happened at run-time.
  7. Optionals require a discussion about NIL

  8. Reinforce the nil-check and offer compile-time cues

  9. Assumes a value must be present, unless told otherwise

  10. An optional must be unwrapped using a ? or !

  11. Protocols

  12. Blueprint

  13. A blueprint of methods, properties, and other requirements that suit

    a particular task or piece of functionality
  14. None
  15. Contract

  16. A guarantee of some terms that will be satisfied. To

    the other party, the contract is a set of obligations.
  17. None
  18. Abstraction Layer

  19. Allows us to Create Delegates

  20. Class that adopts the protocol is referred to as the

  21. One class (a delegator class) would give control or responsibility

    for some behavioral logic to another class called a delegate.
  22. 1. Create a delegate protocol that defines the responsibilities of

    the delegate.
  23. 2. Create a delegate property in the delegating class to

    keep track of the delegate.
  24. 3. Adopt and implement the delegate methods in the delegate

  25. 4. Call the delegate from the delegating object.

  26. Extensions

  27. Added functionality to a Class, Struct or Enum

  28. Adding functionality… Not overwriting it

  29. NO Monkey Patching From Extensions

  30. Increases Readability

  31. Thank you!