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)) // 5All lessons in this course
- SwiftFormat / SwiftLint basics
- Style guide, API design guidelines
- Documenting code (DocC intro)