2021年1月1日星期五

How to print something in SwiftUI in XCode 12.3 "Preview" when a button is clicked (not in Simulator)?

I am trying to print some text in the debug console using the "Preview" in Xcode 12.3 using SwiftUI (not the simulator), and am having issues... nothing appears to show up. I tried right clicking and hitting "Debug Preview" in the preview area.

I also tried a method proposed in a separate post by having a Print function outside of the body, but it also does not work and simple text does not get printed to the console. My code is as follows:

import SwiftUI    extension View {      func Print(_ vars: Any...) -> some View {          for v in vars { print(v) }          return EmptyView()      }  }    struct ContentView: View {    var body: some View {  VStack {                          Button(action: {  print("Hello") // does not get printed                          Print("Hello") // does not get printed  }) {  Text("Click Me")  }  }    }    }  
https://stackoverflow.com/questions/65535425/how-to-print-something-in-swiftui-in-xcode-12-3-preview-when-a-button-is-click January 02, 2021 at 10:04AM

没有评论:

发表评论