Open 7156ccc1-d3b8-4460-882a-3f5802920f8f opened 5 years ago
cc @DougGregor
Here is a concrete example where I need it. I want to extend `DelayedMutable` property wrapper which by itself does not project anything with a projecting behavior if the generic `Value` is some `Binding`. Please don't get confused with SwiftUI's Binding, this is a custom re-implementation for usage in UIKit on older OS's.
// FIXME: Change to
// ```
// @DelayedMutable
// public private(projection) var isEnabled: Binding<Bool>
// ```
private var _isEnabled = DelayedMutable<Binding<Bool>>()
public var isEnabled: Binding<Bool> {
get {
return _isEnabled.wrappedValue
}
set {
// FIXME: Move the following code to `willSet` when possible.
do {
setNeedsLayout()
_updates[^\.isEnabled] = newValue.transaction.disablesAnimations
}
// Update the binding.
_isEnabled.wrappedValue = newValue
}
}
private var _$isEnabled: Bool {
return _isEnabled.projectedValue
}
Ping @DougGregor. Is this a natural implication of the the property wrapper design?
I think it's reasonable for this to work, yes.
Environment
Apple Swift version 5.1 (swiftlang-1100.0.257.2 clang-1100.0.31.3) Target: x86_64-apple-darwin19.0.0Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, PropertyWrappers | |Assignee | None | |Priority | Medium | md5: 0a404a46a1f17b44ccbac70cb9f79037Issue Description:
Related discussion: https://forums.swift.org/t/conditional-projected-property/27152
This code should compile and behave as expected:
Because something like this does already work: