Knowledgebase

Writing Idiomatic Swift Print

  • appletechnology, apple, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Conventions and practice.

WHAT THE LANGUAGE FAVOURS

Clarity at the point of use Value types Immutability Explicit handling of absence and failure

WHAT NAMING CONVENTIONS ARE

Types in one case, members in another Methods named as phrases reading naturally at the call site Boolean properties reading as assertions

WHAT TO DECLARE BY DEFAULT

Constants, not variables.

WHY

It states intent, and the compiler enforces it.

WHAT TO PREFER

Structures over classes, unless identity is needed Protocols over inheritance Extensions to organise code by purpose

WHAT EXTENSIONS ARE USEFUL FOR

Grouping conformance to a protocol with its implementation.

WHAT TO AVOID

Force unwrapping outside genuine programmer errors Deeply nested closures Very long functions Abbreviations that are not universal

WHAT TO USE

Guard statements for early exit The standard collection operations rather than manual loops Access control, restricting visibility by default

WHY ACCESS CONTROL MATTERS

Anything exposed becomes something you cannot change freely.

WHAT TO ADOPT

The formatter and linter, applied automatically.


Was this answer helpful?
Back

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


Trustpilot