Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

NSFuntik/SwiftModernArchitecture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

SwiftUI Modern Clean Architecture

Swift Package Manager Swift Version Platforms License

A lightweight, scalable and modern iOS architecture template based on Clean Architecture principles and SwiftUI.

Overview

This template provides a clean and maintainable architecture for iOS apps with clear separation of concerns, dependency injection, and SwiftUI integration.

Features

  • πŸ— Clean Architecture implementation
  • πŸ“¦ Modular design
  • πŸ”„ Async/await support
  • πŸ’‰ Simple dependency injection
  • πŸ§ͺ Testable by design
  • πŸ“± SwiftUI first
  • 🎯 iOS 15+ & macOS 13+
  • 🧩 Easy to extend

Project Structure

ModernCleanSwiftUI/
β”œβ”€β”€ Sources/
β”‚ β”œβ”€β”€ Domain/
β”‚ β”‚ β”œβ”€β”€ Entity.swift
β”‚ β”‚ β”œβ”€β”€ Repository.swift
β”‚ β”‚ └── ViewState.swift
β”‚ β”œβ”€β”€ Infrastructure/
β”‚ β”‚ β”œβ”€β”€ Network/
β”‚ β”‚ └── Storage/
β”‚ └── Presentation/
β”‚ └── Views/
└── Tests/

Installation

  1. Add the package to your Xcode project:
dependencies: [
 .package(url: "https://github.com/NSFuntik/SwiftModernArchitecture", from: "1.0.0")
]
  1. Import the modules you need:
import Domain
import Presentation
import Infrastructure

Basic Usage

1. Define Your Model

struct User: Entity {
 let id: UUID
 let name: String
}

2. Create a Feature

final class UsersFeature: Feature {
 typealias Input = UserRequest
 typealias Output = [User]
 
 func execute(_ input: Input) async throws -> Output {
 // Implementation
 }
}

3. Create a View

struct UsersView: View {
 var body: some View {
 LoadableView(source: usersFeature, input: .all) { users in
 List(users) { user in 
 Text(user.name)
 }
 }
 }
}

Key Components

Domain Layer

  • Entity: Base protocol for domain models
  • Repository: Data access abstraction
  • Feature: Combined repository and business logic

Infrastructure Layer

  • APIClient: Network communication
  • StorageService: Data persistence

Presentation Layer

  • LoadableView: Data loading container
  • ResourceView: State handling
  • PaginatedView: Pagination support

Best Practices

  1. Keep layers separate and dependencies clean:

    • Domain has no dependencies
    • Infrastructure depends on Domain
    • Presentation depends on Domain
  2. Use dependency injection:

@Inject private var feature: UsersFeature
  1. Handle states properly:
LoadableView(source: feature, input: input) { data in
 // Success state
}
  1. Write tests for each layer:
class FeatureTests: XCTestCase {
 func testFeature() async throws {
 // Test implementation
 }
}

Benefits

  • βœ… Clear separation of concerns
  • βœ… Highly testable architecture
  • βœ… Modern Swift features
  • βœ… SwiftUI integration
  • βœ… Minimal dependencies
  • βœ… Easy to understand and extend
  • βœ… Production ready

Contributing

Contributions are welcome! Please read our contributing guidelines and submit pull requests.

Requirements

  • iOS 15.0+
  • macOS 13.0+
  • Xcode 14.0+
  • Swift 5.9+

License

This project is available under the MIT license.

About

A lightweight, scalable and modern iOS architecture template based on Clean Architecture principles and SwiftUI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /