nalexn /
clean-architecture-swiftui
SwiftUI sample app using Clean Architecture. Examples of working with SwiftData persistence, networking, dependency injection, unit testing, and more.
91/100 healthLoading repository data…
nazmulkp / repository
SwiftUI sample app using Clean Architecture. Examples of working with local and remote data, dependency injection, unit testing, and more.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
ExampleMVVM is an iOS application designed with Clean Architecture principles and SwiftUI modularity. This project demonstrates a scalable, maintainable, and testable architecture, leveraging dependency injection, protocol-oriented programming, and clear separation of concerns.
The project is organized into distinct layers, each responsible for specific concerns:
ExampleMVVMApp.swift: Entry point of the application, responsible for setting up the main window and initializing the dependency injection.
View: Contains SwiftUI views responsible for the UI layout and presentation.
ViewModel: Contains view models that manage UI state and interact with the domain layer.
Interfaces: Defines protocols for repositories and data sources, ensuring a clear contract between layers.
UseCases: Contains business logic and application-specific rules.
Entities: Contains business models representing core domain objects.
Remote: Contains data sources for fetching data from remote APIs.
Selected from shared topics, language and repository description—not editorial ratings.
nalexn /
SwiftUI sample app using Clean Architecture. Examples of working with SwiftData persistence, networking, dependency injection, unit testing, and more.
91/100 healthraviseta /
SwiftUI sample app using Clean Architecture. Examples of working with SwiftData persistence, networking, dependency injection, unit testing, UITesting and SOLID Principals.
43/100 healthMianMHaroon /
Local: Contains data sources for fetching data from local files.
Repositories: Coordinates between data sources and domain layer, transforming data as needed.
Network: Manages network communication details.
Configuration: Manages application configurations.
Utilities: Contains shared utilities and helpers.
Interfaces: Defines protocols for infrastructure components.
The project leverages dependency injection to manage dependencies between layers. This ensures loose coupling and enhances testability. Dependencies are injected through initializers, allowing for easy substitution of implementations during testing.
import SwiftUI
@main
struct ExampleMVVMApp: App {
var body: some Scene {
WindowGroup {
let apiClient = APIClient()
let appConfiguration = AppConfiguration()
let apiConfiguration = WeatherAPIConfiguration(configuration: appConfiguration)
let remoteDataSource = RemoteWeatherDataSource(apiClient: apiClient, apiConfiguration: apiConfiguration)
let jsonLoader = JSONLoader()
let localDataSource = LocalWeatherDataSource(jsonLoader: jsonLoader, configuration: appConfiguration)
let useLocalData = false // Change this to true to use local data
let dataSource: WeatherDataSource = useLocalData ? localDataSource : remoteDataSource
let repository = WeatherRepositoryImpl(dataSource: dataSource)
let fetchWeatherUseCase = FetchWeatherUseCase(repository: repository)
let viewModel = WeatherViewModel(fetchWeatherUseCase: fetchWeatherUseCase)
WeatherView(viewModel: viewModel)
}
}
}
This guide shows a side-by-side comparison of three ways to handle asynchronous tasks in Swift:
func fetchData(completion: @escaping (Result<String, Error>) -> Void) {
guard let url = URL(string: "https://example.com") else { return }
URLSession.shared.dataTask(with: url) { data, response, error in
if let error = error {
completion(.failure(error))
return
}
guard let data = data, let result = String(data: data, encoding: .utf8) else { return }
completion(.success(result))
}.resume()
}
// Usage
fetchData { result in
switch result {
case .success(let data):
print("Data: \(data)")
case .failure(let error):
print("Error: \(error)")
}
}
func fetchData() {
guard let url = URL(string: "https://example.com") else { return }
DispatchQueue.global().async {
if let data = try? Data(contentsOf: url),
let result = String(data: data, encoding: .utf8) {
DispatchQueue.main.async {
print("Data: \(result)")
}
} else {
DispatchQueue.main.async {
print("Error fetching data")
}
}
}
}
// Usage
fetchData()
func fetchData() async throws -> String {
guard let url = URL(string: "https://example.com") else { throw URLError(.badURL) }
let (data, _) = try await URLSession.shared.data(from: url)
guard let result = String(data: data, encoding: .utf8) else { throw URLError(.cannotDecodeContentData) }
return result
}
// Usage
Task {
do {
let data = try await fetchData()
print("Data: \(data)")
} catch {
print("Error: \(error)")
}
}
SwiftUI sample app demonstrating Clean Architecture, MVVM, use cases, FactoryKit DI, and GitHub REST API integration on iOS.
atereshkov /
Swift (UIKit) sample app using Clean Architecture based on MVVM pattern. Examples of data persistence, networking, dependency injection, unit testing and more.
42/100 healthDoylarius /
SwiftUI sample app using Clean Architecture (SwiftData persistence, networking, dependency injection, unit testing, and etc)
59/100 health