An iOS sample application demonstrating clean architecture, comprehensive testing, and modern Swift/SwiftUI development practices. This project showcases integration of local persistence, networking, reactive programming, and dependency injection in a production-ready codebase.
MyLibrary is a personal library manager that allows users to search for books using the Open Library API and save favorites locally. The app demonstrates professional iOS development patterns including MVVM architecture, protocol-oriented design, and test-driven development.
This is sample code intended to demonstrate:
- Clean architecture and separation of concerns
- Comprehensive unit testing with modern Swift Testing framework
- Dependency injection and testability-first design
- Integration of local storage and network APIs
- Reactive programming with Combine
- Modern SwiftUI development with previews
- Search Books: Search the Open Library catalog with debounced queries
- Favorites Management: Save and manage favorite books locally
- Book Details: View detailed information about books
- Offline Support: Favorites stored in local SQLite database
- Real-time Updates: Reactive UI updates using Combine publishers
The app follows MVVM (Model-View-ViewModel) architecture with clear separation of concerns:
┌─────────────────────────────────────────────┐
│ SwiftUI Views │
│ (FavoritesScreen, SearchBooksScreen, etc.) │
└─────────────────┬───────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ View Models │
│ (Business logic, state management) │
└─────────────┬────────────┬──────────────────┘
│ │
▼ ▼
┌─────────────┐ ┌──────────────────┐
│ BookDAO │ │ APIClient │
│ (Database) │ │ (Networking) │
└─────────────┘ └──────────────────┘
│ │
▼ ▼
┌─────────────┐ ┌──────────────────┐
│ GRDB │ │ URLSession │
└─────────────┘ └──────────────────┘
Dependency Injection: Manual DI via Composer pattern with separate configurations for live and preview environments
Protocol-Oriented Design: All dependencies are protocol-based for easy testing and mocking
OpenLibraryAPIClientprotocol with live and fake implementations- Database access layer (DAO) pattern for data operations
Reactive Programming: Combine publishers for real-time data updates
BookDAO.streamBooks()publishes database changes to UI- Debounced search input with configurable delay
Environment-Based Configuration: SwiftUI environment values for dependency injection throughout the view hierarchy
- SwiftUI: Modern declarative UI framework
- Combine: Reactive programming for data streams and async operations
- async/await: Modern Swift concurrency for networking
- GRDB.swift: Type-safe SQLite database with migrations
- Swift Testing: Modern testing framework (not XCTest)
- Swift Package Manager: Dependency management
MyLibrary/
├── Source/
│ ├── App/
│ │ ├── Composer.swift # DI container
│ │ └── MyLibraryApp.swift # App entry point
│ ├── Model/
│ │ └── Book.swift # Domain model
│ ├── Database/
│ │ ├── BookDAO.swift # Data access layer
│ │ └── Database.swift # GRDB setup & migrations
│ ├── Networking/
│ │ ├── OpenLibraryAPIClient.swift # API protocol
│ │ └── Live/ # Production implementation
│ └── UI/
│ ├── Favorites/
│ │ ├── FavoritesScreen.swift
│ │ └── FavoritesViewModel.swift
│ ├── Search Books/
│ │ ├── SearchBooksScreen.swift
│ │ └── SearchBooksViewModel.swift
│ └── Book Details/
│ ├── BookDetailsScreen.swift
│ └── BookDetailsViewModel.swift
└── Tests/
├── Database/
│ └── BookDAOTests.swift
├── Networking/
│ └── LiveOpenLibraryAPIClientTests.swift
└── UI/
├── FavoritesViewModelTests.swift
├── SearchBooksViewModelTests.swift
└── BookDetailsViewModelTests.swift
- Xcode 16.2 or later
- iOS 18.0+ deployment target
- Swift 6.0+
- Clone the repository:
git clone <repository-url>
cd MyLibrary- Open the project:
open MyLibrary.xcodeproj- Build and run:
- Select a simulator or device
- Press
Cmd+Rto build and run
Dependencies are managed via Swift Package Manager and will be resolved automatically on first build.
# Via Xcode
Cmd+U
# Via command line
xcodebuild test -scheme MyLibrary -destination 'platform=iOS Simulator,name=iPhone 16 Pro'The project includes comprehensive unit tests covering:
- ViewModels: Business logic, state management, user interactions
- Data Layer: Database operations (CRUD, queries)
- Network Layer: API client with mocked responses
- Reactive Behavior: Combine publishers and timing
Test-to-source code ratio: ~40% (374 test lines / 561 source lines)
Clear separation between UI and business logic, excellent testability, and natural fit with SwiftUI's reactive nature.
Type-safe, lightweight, better performance for read-heavy operations, and simpler testing with in-memory databases.
Better control over dependency graphs, clearer composition root, and easier to understand for code reviewers. Also supports preview environments elegantly.
Enables testing without hitting real APIs, supports offline development, and makes it easy to swap implementations (useful for different environments or backends).
Better SwiftUI integration for this use case, mature ecosystem, and explicit scheduling control for testing time-based behavior.
This project showcases professional iOS development skills including:
✅ Clean Architecture: Proper layering and separation of concerns ✅ Testability: Protocol-oriented design with comprehensive test coverage ✅ Modern Swift: async/await, Combine, @MainActor, modern concurrency ✅ Database Integration: Schema design, migrations, reactive queries ✅ Networking: Async API client with proper error handling ✅ SwiftUI Mastery: Navigation, state management, environment values, previews ✅ Dependency Injection: Manual DI with composition root pattern ✅ Testing Discipline: Unit tests, mocks/fakes, time-based testing ✅ Code Organization: Clear structure, consistent naming, maintainable codebase
This is sample code for portfolio purposes.
Costa Walcott cwalcott@gmail.com