I’m new to Swift and am trying to learn what’s causing my Views to rerenders? And more specifically, what View are being re-rendered.
I have Self._logChanges()
added the following code, but see nothing in the Console logs in Xcode and nothing in Console.app when monitoring com.apple.SwiftUI
(or anything related). Am I looking in the wrong place or am I using Self._logChanges()
wrong?
import SwiftUI
struct ContentView: View {
@State private var count = 0
var body: some View {
let _ = Self._logChanges()
VStack {
Text("Count: (count)")
.font(.title)
.padding()
Button(action: {
count += 1
}) {
Text("Increment")
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
}
}
}
}
3
As per the release notes:
The new _logChanges() method is like the existing _printChanges() one, except that the new method uses the system console, which is useful in some debugging workflows.
If you want to see changes in Xcode’s console, use Self._printChanges()
instead.
To see changes in the Console.app, run your app in the simulator and then select the simulator in the Console app.
2