Browse Questions
  • A signature proves who sent a payload but says nothing about when, so an attacker who captures a valid signed request can resend it verbatim and it will still verify.
  • Clean Architecture organises code into concentric layers where dependencies only point inward.
  • Timer and CADisplayLink cause memory leaks because the target-action API causes the active RunLoop to retain the timer, and the timer retains its target object until explicitly invalidated.
  • MVVM (Model-View-ViewModel) separates business logic from UI.

Answer: Clean Architecture organises code into concentric layers where dependencies only point inward. The inner layers have no knowledge of the outer layers.

[ UI / Presentation ]
       ↓
[ Use Cases / Interactors ]
       ↓
[ Domain / Entities ]
       ↑
[ Data / Repositories ]  (implements interfaces defined in Domain)

Key rule: The Domain layer has zero imports of UIKit, SwiftUI, or any framework.

Code Example:

// Domain — pure Swift, no framework imports
struct Article { let id: String; let title: String }

protocol ArticleRepository {
    func fetchAll() async throws -> [Article]
}

class FetchArticlesUseCase {
    private let repo: ArticleRepository
    init(repo: ArticleRepository) { self.repo = repo }
    func execute() async throws -> [Article] { try await repo.fetchAll() }
}

// Data layer — implements the protocol
class RemoteArticleRepository: ArticleRepository { ... }

// Presentation layer — uses the use case
class ArticleViewModel: ObservableObject {
    private let useCase: FetchArticlesUseCase
    @Published var articles: [Article] = []
    func load() async { articles = try await useCase.execute() }
}