Fireship · @fireship

Swift in 100 Seconds

Uploaded November 22, 2021 · Length 2:25

Swift in 100 Seconds

Summary

swift language basics and features in 100 seconds, including syntax, memory safety, and object-oriented programming.

  • swift programming language
  • swift basics
  • swift syntax
  • swift memory safety

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    swift a multi-paradigm compiled language

  2. 0:02

    created by apple famous for building

  3. 0:04

    apps that grow inside of apple's walled

  4. 0:06

    garden it was first introduced in 2014

  5. 0:09

    at the worldwide developers conference

  6. 0:10

    and was designed as a modern successor

  7. 0:12

    to objective-c the original apple

  8. 0:14

    platform language that had been in use

  9. 0:16

    since the 1980s swift interops with

  10. 0:18

    objective-c but provides a shorter more

  11. 0:20

    readable syntax and features like memory

  12. 0:23

    safety and type inference to improve

  13. 0:25

    developer productivity today it's used

  14. 0:27

    to build mobile apps on ios desktop apps

  15. 0:29

    on mac os wearable apps for watch os but

  16. 0:32

    is also open source which means it can

  17. 0:34

    be used to build software outside of

  18. 0:36

    apple platforms it compiles to native

  19. 0:38

    machine code and is built on top of the

  20. 0:40

    llvm tool chain like many other modern

  21. 0:42

    languages however it also supports a

  22. 0:44

    readable print loop allowing you to

  23. 0:46

    experiment with code in a playground

  24. 0:47

    without needing to recompile making it a

  25. 0:50

    great language for beginners in addition

  26. 0:52

    it provides memory safety by preventing

  27. 0:54

    you from writing unsafe code by default

  28. 0:56

    and uses automatic reference counting to

  29. 0:58

    manage memory automatically to get

  30. 1:00

    started install it then create a file

  31. 1:02

    ending in.swift your code will start

  32. 1:04

    executing in the global scope there's no

  33. 1:06

    need for a main function create a

  34. 1:08

    variable with the var keyword followed

  35. 1:10

    by its name and value var creates a

  36. 1:12

    mutable variable which means its value

  37. 1:14

    can change in the future let on the

  38. 1:16

    other hand creates an immutable variable

  39. 1:18

    or constant it uses type inference to

  40. 1:21

    strongly type the value as a string but

  41. 1:23

    we can explicitly type it by adding a

  42. 1:25

    semicolon after the variable name every

  43. 1:27

    variable must be initialized with a

  44. 1:29

    value unless the type has a question

  45. 1:31

    mark which makes it an optional type

  46. 1:32

    allowing it to also contain a nil value

  47. 1:35

    it also supports optional chaining

  48. 1:37

    making it really easy to work with nil

  49. 1:38

    values functions are declared with the

  50. 1:40

    fun keyword and will use named

  51. 1:42

    parameters by default place an

  52. 1:43

    underscore before the name to use

  53. 1:45

    positional arguments instead now use a

  54. 1:47

    backslash with parentheses to

  55. 1:49

    interpolate these values into a string

  56. 1:51

    functions in swift are first class

  57. 1:52

    objects they can be passed as arguments

  58. 1:54

    used as return values and nested to

  59. 1:56

    create closures it also supports

  60. 1:58

    object-oriented patterns like classes