-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfproperty wrappersFeature: property wrappersFeature: property wrappers
Description
Previous ID | SR-10859 |
Radar | None |
Original Reporter | ngocluu (JIRA User) |
Type | Bug |
Environment
Swift 5.1. Xcode 11 Beta (11M336w).
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Bug, PropertyWrappers |
Assignee | None |
Priority | Medium |
md5: c9c1759159a05fd13bb298b4803f1838
Issue Description:
BindableObject class:
import SwiftUI
import Combine
final class UserData: BindableObject {
let didChange = PassthroughSubject<Void, Never>()
// PRIVATE SET
private(set) var showFavoritesOnly = false {
didSet {
print("CHANGED")
didChange.send(())
}
}
}
SwiftUI view:
struct ContentView : View {
@EnvironmentObject var userData: UserData
var body: some View {
VStack {
Toggle(isOn: $userData.showFavoritesOnly) {
Text("Favorites only")
}
Button(action: toggle) {
Text("Change")
}
}
}
func toggle() {
$userData.showFavoritesOnly.value.toggle()
}
}
The property of BindableObject is private(set), but it can be set from the view via Binding.
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfproperty wrappersFeature: property wrappersFeature: property wrappers