Knowledgebase

Swift in Depth: Everything That Matters, Briefly Print

  • appletechnology, apple, errors, troubleshooting, guide, howto, solution, zillionkinghost
  • 0

The summary.

VALUE TYPES ARE THE DEFAULT FOR A REASON

Copies cannot be changed unexpectedly by other code, and they cannot form reference cycles.

Use a class when identity matters or sharing is deliberate.

MODEL STATE SO INVALID STATES CANNOT BE EXPRESSED

Enumerations with associated values, with the compiler requiring every case to be handled.

ASK OF EVERY FORCE UNWRAP: WHAT IF THIS IS NOTHING?

Defensible only where absence indicates a programming error. Never for anything from input, the network or storage.

SMALL PROTOCOLS DESCRIBING ONE CAPABILITY

Large ones force conforming types to implement what they do not need.

ERRORS ARE VISIBLE IN THE SIGNATURE — USE THAT

Propagate what you cannot act on, add context, and never catch everything and continue silently.

ACTORS TURN DATA RACES INTO COMPILE-TIME PROBLEMS

Mark anything touching the interface as main-actor, and always support cancellation.

CAPTURE WEAKLY IN CLOSURES

Memory rising as screens open and close and never falling is the signature of a retain cycle. The memory graph shows what retains an object.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot