Skip to content

Conversation

maykonmeneghel
Copy link
Owner

@maykonmeneghel maykonmeneghel commented Feb 20, 2025

Article:

Description:

1️⃣ Refactored ContentViewModel to use @observableobject correctly

ContentViewModel now correctly conforms to the ObservableObject protocol, ensuring that the SwiftUI UI responds to state changes.

2️⃣ Updated ViewModel lifecycle in ContentView

ContentView now correctly manages the ContentViewModel instance using @StateObject, ensuring that the ViewModel is preserved throughout the View's lifecycle.

Created an initializer in ContentView that accepts a ContentViewModel, allowing greater flexibility in dependency injection.

3️⃣ Use of async / await to improve asynchronous execution

The fetchContents() in ContentViewModel is now fully asynchronous (async throws), avoiding blocking in the UI.
ContentView now uses .task { try await viewModel.fetchContents() }, ensuring that data fetching occurs correctly without blocking screen rendering.

4️⃣ Using actors and isolated let to improve concurrency and security

ContentRepositoryImpl has been transformed into an actor, ensuring that concurrent accesses are safe.
Using isolated let inside the actor to optimize performance, ensuring that datasource is a safe and immutable value.

@observableobject
Copy link

observableobject commented Feb 21, 2025 via email

@maykonmeneghel maykonmeneghel self-assigned this Mar 5, 2025
@maykonmeneghel maykonmeneghel added the enhancement New feature or request label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants