I want to use code such as the following:
import Foundation
import Combine
import SwiftUI
final class DataStore: ObservableObject {
@Published var bools: [Bool] = [true, false]
}
struct ContentView: View {
@EnvironmentObject var dataStore: DataStore
var body: some View {
HStack {
Spacer()
Toggle(isOn: $dataStore.bools[0]) {
Text(dataStore.bools[0] ? "On" : "Off")
}
Spacer()
Toggle(isOn: $dataStore.bools[1]) {
Text(dataStore.bools[1] ? "On" : "Off")
}
Spacer()
}
}
}
(Actually this code is quite useless, but it's just about that I want to pass an element of an array as a binding to a subview.)
In Xcode beta 2 this worked, but since beta 5 I get the following warning on both the "Toggle" lines:
'subscript(_:)' is deprecated: See Release Notes for migration path. And the app crashes when I try to launch it.
Indeed, I have read the release notes, and I believe that the issue has something to do with that "the Binding structure’s conditional conformance to the Collection protocol is removed".
The problem is that I don't understand how to use the sample code that they give with the code that I want to use. Can someone help me with that?