Skip to the content ForoHackers
Log inJoin

Swift: start here

Swift
#3069 · · Quote · Report

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

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply