0

Starting from the simple iOS App template, I make my "ContentView.swift":

import SwiftUI

struct ContentView: View {
  var body: some View {
    Button(action: {
      print("hello console!")
    }, label: {
      Text("Button")
    })
  }
}

struct ContentView_Previews: PreviewProvider {
  static var previews: some View {
    ContentView()
  }
}

I start up a preview in Debug Preview, I activate the console so it shows up below, I see my button that says "Button". I click the button on the text that says "Button", but still see nothing. What am I missing??

Justin Bishop
  • 157
  • 1
  • 8

1 Answers1

1

You need to enable Debug Preview.

From SwiftUI tips and tricks:

If you press play in the SwiftUI preview to try out your designs, you’ll find that any calls to print() are ignored. If you’re using print() for testing purposes – e.g. as simple button tap actions – then this can be a real headache.

Fortunately, there’s a simple fix: right-click on the play button in the preview canvas and choose “Debug Preview”. With that small change made you’ll find your print() calls work as normal.

pawello2222
  • 46,897
  • 22
  • 145
  • 209
  • thanks pawello2222, but that is what I'm doing. it's in "Debug Preview", and still nothing prints out. – Justin Bishop Sep 28 '20 at 00:10
  • well searching around I find several people with the same problem. who have, like me, been careful to use `Debug Preview` and to actually enable the debug console below. So frustrating. – Justin Bishop Sep 28 '20 at 01:35