-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use BindableStore to generate bindings
- Loading branch information
1 parent
2be92b5
commit f1ae774
Showing
4 changed files
with
50 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
Samples/SwiftUITestbed/Sources/Observation/BindableStore.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copied from https://github.com/pointfreeco/swift-composable-architecture/blob/acfbab4290adda4e47026d059db36361958d495c/Sources/ComposableArchitecture/Observation/BindableStore.swift | ||
|
||
import ComposableArchitecture | ||
import SwiftUI | ||
|
||
/// A property wrapper type that supports creating bindings to the mutable properties of a | ||
/// ``Store``. | ||
/// | ||
/// Use this property wrapper in iOS 16, macOS 13, tvOS 16, watchOS 9, and earlier, when `@Bindable` | ||
/// is unavailable, to derive bindings to properties of your features. | ||
/// | ||
/// If you are targeting iOS 17, macOS 14, tvOS 17, watchOS 9, or later, then you can replace | ||
/// ``BindableStore`` with SwiftUI's `@Bindable`. | ||
@available(iOS, deprecated: 17, renamed: "Bindable") | ||
@available(macOS, deprecated: 14, renamed: "Bindable") | ||
@available(tvOS, deprecated: 17, renamed: "Bindable") | ||
@available(watchOS, deprecated: 10, renamed: "Bindable") | ||
@propertyWrapper | ||
@dynamicMemberLookup | ||
public struct BindableStore<State: ObservableState> { | ||
public var wrappedValue: Store<State> | ||
public init(wrappedValue: Store<State>) { | ||
self.wrappedValue = wrappedValue | ||
} | ||
|
||
public var projectedValue: BindableStore<State> { | ||
self | ||
} | ||
|
||
public subscript<Subject>( | ||
dynamicMember keyPath: ReferenceWritableKeyPath<Store<State>, Subject> | ||
) -> Binding<Subject> { | ||
Binding( | ||
get: { self.wrappedValue[keyPath: keyPath] }, | ||
set: { self.wrappedValue[keyPath: keyPath] = $0 } | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters