@Shared behavior in Xcode previews appears to have changed with Xcode 26 #171
Unanswered
kevinanderson7
asked this question in
Q&A
Replies: 1 comment
-
I am seeing the same issue in Xcode 26 beta 2. Previews appear to be, well, sharing a single shared value. I'm using an in-memory key defined like this: extension SharedKey where Self == InMemoryKey<Bool>.Default {
static var isRecording: Self {
Self[.inMemory("isRecording"), default: false]
}
} I'm actually not sure what the recommended way is to populate shared values in previews. I've tried this: @Previewable @Shared(.isRecording) var isRecording = false And this: #Preview {
@Previewable @Shared(.isRecording) var isRecording
MyView()
.onAppear { $isRecording.withLock { $0 = false }
} But I'm not sure which, if either, is preferred. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In Xcode 26 beta 1 and beta 2, I have noticed unusual behavior when using the Shared property wrapper in Xcode previews. Before the Xcode 26 beta, it was easy to configure multiple previews in a given file to use different Shared values so that each preview could be spun up in a very specific state. For Xcode 26 beta 1 and 2, I have noticed that while this once worked great in previous Xcode versions, it no longer seems to produce the correct result.
I have provided a link to a repro here: https://github.com/kevinanderson7/swift-sharing/tree/xcode-previews-repro.
If I build the Xcode previews with Xcode 26 beta 1 or 2, the Shared value declared in the first preview of the file is the only one used across the 2 other previews. However if I build the Xcode previews using Xcode 16.4, each preview is spun up with the proper Shared value. Any idea why this might be?
Beta Was this translation helpful? Give feedback.
All reactions