Skip to content

Instantly share code, notes, and snippets.

@mchakravarty
Created September 9, 2020 13:50
Show Gist options
  • Select an option

  • Save mchakravarty/afd2e1ff3629d2afbd1ffbc10fb00bc6 to your computer and use it in GitHub Desktop.

Select an option

Save mchakravarty/afd2e1ff3629d2afbd1ffbc10fb00bc6 to your computer and use it in GitHub Desktop.
SwiftUI AttributeGraph cycle in playground only
// Put this into an Xcode 12.0 multiplatform app
import SwiftUI
struct ContentView: View {
@State var text = "Hello!"
var body: some View {
VStack {
TextEditor(text: $text)
HStack {
Spacer()
Text("\(text.count) characters")
}
}
}
}
@main
struct CountingEditorAppApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
// Put this into an Xcode 12.0 iOS playground
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
@State var text = "Hello!"
var body: some View {
VStack {
TextEditor(text: $text)
HStack {
Spacer()
Text("\(text.count) characters")
}
}
}
}
import PlaygroundSupport
PlaygroundPage.current.setLiveView(ContentView())
@mchakravarty

Copy link
Copy Markdown
Author

The first version (in a standalone app) works just fine. The second version in an iOS playground leads to warnings of the form === AttributeGraph: cycle detected through attribute 5336 === in the Xcode debug area and, at the same time, the view is not very responsive and sometimes skips updates.

What is the problem here? This behaviour makes it quite awkward to test (and experiment) with some SwiftUI views in Xcode playgrounds.

@bsrz

bsrz commented Mar 17, 2021

Copy link
Copy Markdown

@mchakravarty experiencing the same in Xcode 12.4, did you ever find out what was the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment