Browse Questions
  • All three separate concerns between data, UI, and logic — but they differ in how the middle layer connects to the view.
  • Clean Architecture organises code into concentric layers where dependencies only point inward.
  • SOLID is five principles for writing maintainable, extensible code.
  • @ViewBuilder is a result builder that lets you write multiple views inside a closure and have them composed into a single view.

Answer: SOLID is five principles for writing maintainable, extensible code.

S — Single Responsibility: A type should do one thing.

// ❌ ViewController fetching, parsing, and displaying
// ✅ Separate into ViewController + ViewModel + Repository

O — Open/Closed: Open for extension, closed for modification.

protocol PaymentMethod { func pay(amount: Double) }
struct ApplePay: PaymentMethod { func pay(amount: Double) { } }
struct CreditCard: PaymentMethod { func pay(amount: Double) { } }
// Add new payment types without changing existing code

L — Liskov Substitution: Subtypes must be substitutable for base types.

// Any ArticleRepository implementation should work wherever the protocol is used

I — Interface Segregation: Prefer small, focused protocols.

protocol Readable { func read() -> Data }
protocol Writable { func write(_ data: Data) }
// Rather than one large DataStore protocol

D — Dependency Inversion: Depend on abstractions, not concretions.

class ViewModel {
    let repo: ArticleRepository  // protocol, not RemoteArticleRepository
}