Core Architectural Patterns
MVVM
Model-View-ViewModel for clear separation of concerns
Actor Pattern
Thread-safe service layer using Swift actors
Declarative UI
SwiftUI for reactive, declarative interfaces
Async/Await
Modern concurrency for clean async code
MVVM Pattern
Breeze implements the Model-View-ViewModel pattern for clear separation between UI and business logic.Architecture Flow
ViewModel Example
TheDashboardViewModel demonstrates the MVVM pattern:
Key MVVM Characteristics:
@Publishedproperties for reactive state updates@MainActorensures UI updates on main thread- Business logic separated from UI
- Computed properties for derived state
View Observing ViewModel
Actor Pattern for Services
All services use Swift’sactor pattern for thread-safe API communication.
Why Actors?
Thread Safety
Thread Safety
Actors ensure only one task can access mutable state at a time, preventing data races.
Automatic Synchronization
Automatic Synchronization
Swift automatically manages synchronization - no manual locks or dispatch queues needed.
Compiler Enforcement
Compiler Enforcement
The compiler enforces safe concurrent access patterns at compile time.
Service Actor Example
Actor Benefits:
actorkeyword makes the entire class thread-safe- Methods are implicitly
asyncwhen called from outside - Shared singleton pattern (
static let shared) is safe - No manual synchronization needed
Calling Actor Methods
Actor methods requireawait when called from outside:
Calling Actors
Async/Await Pattern
Breeze uses Swift’s modern concurrency with async/await for clean asynchronous code.Parallel vs Sequential Fetching
SwiftUI Declarative Patterns
Breeze embraces SwiftUI’s declarative approach for building UIs.Property Wrappers
Conditional Rendering
View Composition
Breeze breaks down complex views into smaller components:View Composition
Each component is self-contained and reusable, making the code easier to test and maintain.
Model Pattern
Models are simple, immutable data structures conforming toCodable.
Why struct over class?
Why struct over class?
- Value semantics (copying instead of referencing)
- Thread-safe by default
- No reference counting overhead
- Perfect for immutable data
Why Codable?
Why Codable?
- Automatic JSON encoding/decoding
- Type-safe API responses
- Custom key mapping with
CodingKeys
Pattern Summary
MVVM
- ViewModels manage state
- Views observe and render
- Models represent data
- Clear separation of concerns
Actor Pattern
- Thread-safe services
- Compiler-enforced safety
- No manual synchronization
- Singleton pattern with
static let
Async/Await
- Clean asynchronous code
- Parallel and sequential fetching
- Error handling with try/catch
- Task-based concurrency
SwiftUI
- Declarative UI syntax
- Reactive data binding
- View composition
- State-driven rendering
Best Practices
1
Keep ViewModels focused
One ViewModel per major screen. Extract shared logic into separate services or utilities.
2
Use actors for shared state
Any service that manages shared mutable state should be an actor for thread safety.
3
Prefer async/await over callbacks
Modern concurrency is clearer and less error-prone than completion handlers.
4
Keep views small
Break down complex views into smaller, reusable components.
5
Use @MainActor for ViewModels
Ensures all UI updates happen on the main thread automatically.
Next Steps
Project Structure
Understand the file organization
Services Reference
Explore service implementations