Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Jan 12, 2024
1 parent 9ffb14f commit 17b7455
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Sources/Perception/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@ import SwiftUI
@available(watchOS, introduced: 6, obsoleted: 10)
@available(visionOS, unavailable)
extension Environment {
/// Creates an environment property to read a perceptible object from the environment.
///
/// A backport of SwiftUI's `Environment.init` that takes an observable object.
///
/// - Parameter objectType: The type of the `Perceptible` object to read from the environment.
@_disfavoredOverload
public init(_ objectType: Value.Type) where Value: AnyObject & Perceptible {
self.init(\.[unwrap: \Value.self])
}

/// Creates an environment property to read a perceptible object from the environment, returning
/// `nil` if no corresponding object has been set in the current view's environment.
///
/// A backport of SwiftUI's `Environment.init` that takes an observable object.
///
/// - Parameter objectType: The type of the `Perceptible` object to read from the environment.
@_disfavoredOverload
public init<T: AnyObject & Perceptible>(_ objectType: T.Type) where Value == T? {
self.init(\.[\T.self])
Expand All @@ -23,6 +34,13 @@ extension Environment {
@available(watchOS, introduced: 6, obsoleted: 10)
@available(visionOS, unavailable)
extension View {
/// Places a perceptible object in the view’s environment.
///
/// A backport of SwiftUI's `View.environment` that takes an observable object.
///
/// - Parameter object: The object to set for this object's type in the environment, or `nil` to
/// clear an object of this type from the environment.
/// - Returns: A view that has the specified object in its environment.
@_disfavoredOverload
public func environment<T: AnyObject & Perceptible>(_ object: T?) -> some View {
self.environment(\.[\T.self], object)
Expand Down

0 comments on commit 17b7455

Please sign in to comment.