0Pricing
Swift Academy · Lesson

Style guide, API design guidelines

Use clear names , thoughtful argument labels , sensible defaults , and concise doc comments to design friendly Swift APIs.

Principles

Good APIs are readable, predictable, and small.

  • Names that describe intent
  • Useful argument labels
  • Defaults for common cases
  • Concise docs and examples

Naming basics

Actions => verbs, data => nouns. Avoid abbreviations that hide meaning.

// Prefer clear, simple names.
// BAD:
func doCalc(_ a: Int, _ b: Int) -> Int { a + b }

// GOOD:
func sum(_ a: Int, _ b: Int) -> Int { a + b }

// BAD (ambiguous):
struct Cfg { let v: Int }
// GOOD (nouns for data types):
struct Configuration { let retries: Int }

print(sum(2, 3))  // 5

All lessons in this course

  1. SwiftFormat / SwiftLint basics
  2. Style guide, API design guidelines
  3. Documenting code (DocC intro)
← Back to Swift Academy