Saltar al contenido ForoHackers

Swift: start here

Swift
#563 · Ophuscado · · Denunciar

Swift is a compiled, statically typed language designed to be safe, fast and expressive. It is the main language for apps on Apple's platforms and also runs on servers and other systems. It avoids whole families of errors with optionals and strict initialisation, and mixes value types, protocols and a functional flavour.

Key concepts

  • Optionals: a value that may be absent has its own type, which you must unwrap before use.
  • Value and reference types: structs and enums are copied; classes are shared and reference counted.
  • Protocols and extensions: behaviour described by protocols, added to types with extensions, in preference to deep inheritance.
  • Enums with associated values: data that is one of several shapes, matched exhaustively.
  • Memory management: automatic reference counting, and the cycles it cannot break by itself.
  • Structured concurrency: async functions, tasks and actors that isolate mutable state.

Vocabulary

  • ARC: automatic reference counting, how classes are freed.
  • Closure: an anonymous function that captures values.
  • Property wrapper: a reusable type that adds behaviour to a stored property.
  • Package manager: the tool that builds Swift projects and fetches dependencies.

What to study, in order

  1. Basic syntax, constants and variables, collections, control flow, in a playground or a command-line program.
  2. Optionals, structs versus classes, and enums with pattern matching.
  3. Protocols, extensions and generics; model a small domain.
  4. Closures, error handling with throws, and ARC with weak references.
  5. Async and await, tasks and actors.
  6. Build a small app for your target platform with tests.

Related tags

#ios #macos #mobile-computing #functional-programming

Inicia sesión o únete para responder.