Browse Questions
- Because a struct is a value type, declaring the instance with let makes the entire value immutable — including all of its var stored properties.
- Clean Architecture organises code into concentric layers where dependencies only point inward.
- Xcode's Memory Graph Debugger visualizes live heap allocations and object reference relationships, while Malloc Stack Logging reveals the exact source code line where leaked memory was allocated.
- Unstructured Task { ...
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() }
}