Created
September 9, 2020 13:50
-
-
Save mchakravarty/afd2e1ff3629d2afbd1ffbc10fb00bc6 to your computer and use it in GitHub Desktop.
SwiftUI AttributeGraph cycle in playground only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.