Learn Courses My Dashboard

Lesson 10 Challenge (14 day challenge)

So I was able to build the button for the challenge, but I am unable to get the console view button to appear in normal view outside of the playground. Any advice?

Here is the code that I wrote.

//
//  ContentView.swift
//  Lesson10Challenge
//
//  Created by Charles Beecroft on 5/14/21.
//

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack{
            Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/, label: {
                /*@START_MENU_TOKEN@*/Text("Button")/*@END_MENU_TOKEN@*/
            })
            
            Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/, label: {
                HStack{
                    Image("dealbutton")
                }
            })
        }
    }
}

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

Any advice?

Hi Charles,

Sorry that nobody responded to your question earlier.

Assuming that you have added the dealbutton images to your assets catalogue you should see something like this in your preview depending on the simulator you have chosen.

The challenge says to place the buttons side by side so rather than use a VStack which places them one above the other, change it to a HStack so that it will look something like this:

The other part of the challenge is to print something to the console when each button is tapped so in the action: closure (between the curly braces) add a print statement which will print to the Console. Your code could then look something like this:

struct ContentView: View {
    var body: some View {
            HStack{
                Button(action: {
                    print("Button pressed")
                }, label: {
                    Text("Button")
                })

                Button(action: {
                    print("Deal Button pressed")
                }, label: {
                    HStack{
                        Image("dealbutton")
                    }
                })
            }
        }
}

The preview does not print to the console when you go live so you have to run the code in the simulator.

That does work. Still I don’t know how to get the console to appear on my screen. The only thing that shows up is the simulator and the view pane for adding code into.

@ebeecroft

The Console can be activated via the Xcode menu View > Debug Area > Activate Console or by the short cut key combination Shift + Command + C

I have no idea what is going on. The console is not showing any output from my two print statements.

When in Preview Mode nothing is output to the Console. You need to run the App in a simulator to see Console output.

That is something I didn’t know about. The print statements work fine in the simulator.