Skip to content

Migrate from ObservableObject to @Observable (Swift Observation)#653

Merged
IvanStepanok merged 65 commits intoopenedx:developfrom
raccoongang:feat/Observable-migration
Mar 17, 2026
Merged

Migrate from ObservableObject to @Observable (Swift Observation)#653
IvanStepanok merged 65 commits intoopenedx:developfrom
raccoongang:feat/Observable-migration

Conversation

@Demian-Yushyn
Copy link
Copy Markdown
Contributor

This PR migrates ViewModels from the ObservableObject protocol and @Publishedproperties to the new Swift Observation macro @Observable.

As part of this change, the project now targets iOS 17+ as the minimum deployment version, allowing us to rely on modern SwiftUI and observation APIs without backward-compatibility workarounds.

Motivation

ObservableObject + @Published requires a significant amount of manual work and is error-prone:
properties must be explicitly marked as @Published, it’s easy to forget to publish changes, objectWillChange is implicit and not type-safe.

With iOS 17 as the minimum supported version, we can safely adopt Swift’s @Observable macro, which provides a compiler-generated, first-class observation mechanism that is:

  • safer
  • more concise
  • easier to reason about
  • officially supported and forward-looking

What changed

Before


class SomeViewModel: ObservableObject {
    @Published var value: Int = 0
}

After


@Observable
class SomeViewModel {
    var value: Int = 0
}

Benefits

  • Less boilerplate
  • No need for ObservableObject, @Published, or manual change notifications.
  • Fewer bugs
  • All mutable properties are observable by default — no risk of forgetting to publish state changes.
  • Cleaner ViewModels
  • Models focus on business logic instead of SwiftUI plumbing.
  • Better performance characteristics
  • Observation code is generated at compile time, enabling better compiler optimizations.
  • Future-proof architecture
  • By targeting iOS 17+, the codebase fully embraces modern SwiftUI and Swift concurrency APIs.

Demian-Yushyn and others added 30 commits September 16, 2025 11:05
Migrated Course Unit View, CourseContainerViewModel, SignInViewModel, BaseCourseViewModel
Swift, replacing `@ObservedObject` and `@StateObject`.

This modernizes the data flow and simplifies the code by leveraging the compiler to automatically manage observation.
Also it increases the minimum iOS deployment target to 17.0
Updates the iOS deployment target to version 17.0 in the project settings.

Refactors the course outline and progress view to handle loading states correctly.
@mphilbrick211 mphilbrick211 moved this from Waiting on Author to Ready for Review in Contributions Feb 25, 2026
@mphilbrick211 mphilbrick211 requested a review from a team February 25, 2026 20:26
@IvanStepanok IvanStepanok self-assigned this Mar 16, 2026
@IvanStepanok IvanStepanok self-requested a review March 16, 2026 18:33
Copy link
Copy Markdown
Contributor

@IvanStepanok IvanStepanok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’ve put in a tremendous amount of work! Thank you so much!

@IvanStepanok IvanStepanok merged commit a8e722e into openedx:develop Mar 17, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from Ready for Review to Done in Contributions Mar 17, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@0792ece). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff            @@
##             develop   #653   +/-   ##
========================================
  Coverage           ?      0           
========================================
  Files              ?      0           
  Lines              ?      0           
  Branches           ?      0           
========================================
  Hits               ?      0           
  Misses             ?      0           
  Partials           ?      0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants