-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Picker binding triggers runtime warnings in iOS 18 #100
Comments
I am experiencing the same issue in the context of a TCA feature. The warning is raised by the selection binding of the Picker. When building with Xcode 15.4.0 there is no runtime waring, but when building with Xcode 16.0.0 there is a runtime warning. Wrapping the Picker in @Reducer
struct ContentFeature: Reducer {
@ObservableState
struct State: Equatable {
let indices = [0, 1, 2]
var index: Int = 0
}
enum Action {
case indexChanged(Int)
}
var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
case .indexChanged(let index):
state.index = index
return .none
}
}
}
}
struct ContentView: View {
@Perception.Bindable var store: StoreOf<ContentFeature>
var body: some View {
List {
Label("Hello World", systemImage: "globe")
WithPerceptionTracking {
Picker("Picker", selection: $store.index.sending(\.indexChanged)) {
WithPerceptionTracking {
ForEach(store.indices, id: \.self) { index in
Text("Number \(index)")
.tag(index)
}
}
}
}
}
}
} PickerPerceptionTrackingSample.zip Technical information
|
We are encountering the same issue. For now we managed to workaround the warning with a Picker wrapper type based on @KaiOelfke solution from a slack thread: public struct _Picker<Label, SelectionValue, Content>: View
where Label: View, SelectionValue: Hashable, Content: View {
let label: Label
let content: Content
let selection: Binding<SelectionValue>
public init(
_ titleKey: LocalizedStringKey,
selection: Binding<SelectionValue>,
@ViewBuilder content: () -> Content
) where Label == Text {
self.label = Text(titleKey)
self.content = content()
self.selection = selection
}
public var body: some View {
_PerceptionLocals.$skipPerceptionChecking.withValue(true) {
Picker(selection: selection, content: { content }, label: { label })
}
}
} |
Description
A SwiftUI
Picker
bound to a@Perceptible
model triggers the "Perceptible state was accessed but is not being tracked" runtime warnings in iOS 18.It seems to be due to access to the selection binding from the resolved body style. Example stack trace below.
Example stack trace
Checklist
@Observable
macro or another tool from theObservation
framework, please file it directly with Apple.main
branch of this package.Expected behavior
No warning for this case.
Actual behavior
Spurious runtime warnings.
Steps to reproduce
I was able to reproduce with this view dropped into the Perception example app. The warning is triggered on first render.
Perception version information
1.3.5
Destination operating system
iOS 18.0
Xcode version information
Version 16.0 (16A242d)
Swift Compiler version information
The text was updated successfully, but these errors were encountered: