8000 GitHub - eFog-R/OpenObservation
[go: up one dir, main page]

Skip to content

eFog-R/OpenObservation

 
 

Repository files navigation

OpenObservation

Backport implementation of Swift's Observation framework with access to @_spi(SwiftUI) APIs.

CI Status
macOS
Ubuntu

Purpose

The official Observation framework in Swift Toolchain doesn't ship with package.swiftinterface, preventing direct use of @_spi(SwiftUI) APIs. There are two solutions to this problem, but this project provides solution 2:

  1. Manual workaround (not included): Construct a package.swiftinterface and add it to the toolchain (⚠️ No API stability, may break between toolchain versions)

  2. OpenObservation approach (this project): Reimplement Observation framework, allowing OpenSwiftUI to import it via @_spi(OpenSwiftUI)

Implementation Status

The current implementation is aligned with Swift's release/6.1 branch implementation of the Observation framework.

Features

  • Full Observation framework implementation
  • Cross-platform support (macOS, iOS, tvOS, watchOS)
  • @Observable macro support
  • Thread-safe tracking
  • Pure Swift fallback for platforms without toolchain support

Installation

dependencies: [
    .package(url: "https://github.com/OpenSwiftUIProject/OpenObservation", from: "1.0.0")
]

Documentation

Comprehensive documentation is available on Swift Package Index.

Usage

import OpenObservation

@Observable
class Counter {
    var value: Int = 0
    
    func increment() {
        value += 1
    }
}

// Use with ObservationTracking
let counter = Counter()
withObservationTracking {
    print("Counter value: \(counter.value)")
} onChange: {
    print("Counter changed!")
}

Configuration

  • OPENSWIFTUI_SWIFT_TOOLCHAIN_SUPPORTED: Enable Swift toolchain runtime implementation (auto-detected)
    • Config OPENSWIFTUI_SWIFT_TOOLCHAIN_PATH and OPENSWIFTUI_SWIFT_TOOLCHAIN_VERSION
  • OPENOBSERVATION_DEVELOPMENT: Development mode

License

  • OpenObservation code: MIT License
  • Code derived from Swift project: Apache License v2.0 with Runtime Library Exception

See LICENSE file.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 97.4%
  • C++ 2.6%
0